Test Instructions: give the abcde/fghij = N, where a, B, C, D,e, F, G, H, I, J for any number in the 0~9, can not be duplicated, therefore constitute two five digits (can have a leading 0), the two The number is divisible by N. The topic gives n, asks all the formulas that satisfy the requirement, and divides the output from large to small by the divisor (dividend as well). An N corresponds to the output of a set of answers, an empty line between each set of answers, and if not, the output "there is no solutions for N."
idea: The basic idea is to enumerate. However, it is not necessary to arrange the 10 numbers in full and then one by one to verify. When n is obtained, the upper and lower bounds of the divisor can be calculated, and then the divisor is enumerated in the upper and lower bounds to find the divisor that matches the condition.
The upper bound of the divisor: because the divisor *n the number, must be five digits, so the divisor must satisfy the divisor * N < 100000, that is, the divisor maximum is ceil (100000/n)-1, where ceil () is the ceiling function
The lower bound of the divisor: if you do not consider N, you can actually get the lower bound of the divisor is 01234, this number for the number of people do not repeat and you are in the 0~9 of the maximum four digits, similar, because the divisor *n the number must be five digits, so the divisor must meet the divisor * N >= 10000, the minimum number of base Floor (10000/n) or 01234, where floors () is a flooring function, you need to compare the maximum value of the lower divisor
#include <iostream> #include <cstring> #include <cstdio> #include <cmath>using namespace std; BOOL Isokay (int A, int B) { int vis[10] = {0}; for (int i=0; i<5; i++) { vis[a%10] + +; VIS[B%10] + +; A/= Ten; B/=; } for (int i=0; i<10; i++) { if (vis[i]! = 1) { return false; } } return true;} int main () { int N; int case = 0; while (CIN >> n && N) { if (case) { printf ("\ n"); } case + +; BOOL flag = FALSE; for (int i=10000/n >= 1234? 10000/n: 1234; i < ceil (100000/n); i++) { if (Isokay (I*n, i)) { flag = true; printf ("%.5d/%.5d =%d\n", I*n, I, n); } } if (!flag) { printf ("There is no solutions for%d.\n", n); } } return 0;}
Uva 725 Division