Write a program, finds and displays all pairs of 5-digit numbers, between them use the digits 0through 9 once each, such the first number divided by the second are equal to an integer N, where. That's,
Abcde/fghij = N
Where each letter represents a different digit. The first digit of the numerals is allowed to be zero.
InputEach line of the input file consists of a valid integerN. An input of zero was to terminate the program.
OutputYour Program has to display all qualifying pairs of numerals, sorted by increasing numerator (and, of course, denomin Ator).
Your output should is in the following general form:
xxxxx/xxxxx = N
xxxxx/xxxxx = N
.
.
In case there is no pairs of numerals satisfying the condition, you must write 'there is no solutions for N.". Separate the output for both different values of N by a blank line.
Sample Input
61620
Sample Output
There is no solutions for 61.79546/01283 = 6294736/01528 = 62
Brute force Solver, enumerating the second number
#include <iostream> #include <stdio.h> #include <algorithm> #include <cstring> #include <map > #include <set>using namespace Std;int a[11],n;int is (int i) {if (a[i]==1) return 1; return 0;} int judge (int i,int j,int k,int o,int p) {int x,s,s1,s2; memset (A,0,sizeof (a)); a[i]++;a[j]++;a[k]++;a[o]++;a[p]++; S1=10000*i+1000*j+100*k+10*o+p; S=s1*n; S2=s; while (s) {a[s%10]++; s/=10; } if (is (1) &&is (2) &&is (3) &&is (4) &&is (5) &&is (6) &&is (7) && Is (8) &&is (9) &&is (0)) {printf ("%d/%05d =%d\n", s2,s1,n); return 1;} else return 0;} int main () {int i,j,k,o,p,t=0; while (scanf ("%d", &n), n) {t++; if (t!=1) puts (""); int e=0; For (i=0, i<=9; i++) for (j=0; j<=9; j + +) for (k=0; k<=9; k++) for (o=0; o<=9; o++) for (p= 0; p<=9; p++) if (judge (i,j,k,o,p)) e=1; if (!e) printf ("There is no solutions for%d.\n", N); } return 0;}
UVA 725-division