本题较为简单,将不会编写算法分析说明与代码编写指导。
AC 代码(0 ms):
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<bitset>
#include<algorithm>
#pragma warning(disable:4996)
using namespace std;
bitset<10> appeared;
int main() {
unsigned n, D; bool first = true, nosolution;
for (;;) {
scanf("%u", &n); if (n == 0)return 0;
if (first == true)first = false;
else putchar('\n');
nosolution = true;
for (unsigned d = max((unsigned)1234, 10000 / n);; ++d) {
D = d * n; if (D > 98765)break;
appeared.reset(); if (d < 10000)appeared[0] = 1;
for (unsigned i = D; i != 0; i /= 10) { appeared[i % 10] = 1; }
for (unsigned i = d; i != 0; i /= 10) { appeared[i % 10] = 1; }
if (appeared.all() == true) { nosolution = false; printf("%u / %05u = %u\n", D, d, n); }
}
if (nosolution == true)printf("There are no solutions for %u.\n", n);
}
}