广搜
View Code
#include#include #include #include using namespace std;#define maxn 10000000int n;long long q[maxn];long long work(){ int front = 0; int rear = 0; q[rear++] = 1; while (1) { long long temp = q[front++]; if ((temp * 10) % n == 0) return temp * 10; if ((temp * 10 + 1) % n == 0) return temp * 10 + 1; q[rear++] = temp * 10; q[rear++] = temp * 10 + 1; } return -1;}int main(){// for (n = 1; n <= 200; n++)// printf("%lld\n", work()); while (scanf("%d", &n), n) printf("%lld\n", work());}