1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
#include <bits/stdc++.h> using namespace std;
const int M = (int)1e2;
bool flag; int ans[M + 5];
void dfs(int pos, int k, int n) { if(flag '' pos > M) return; if(!k) { flag = 1; ans[pos] = -1; return; } ans[pos] = 0; dfs(pos + 1, (k * 10) % n, n); if(flag '' pos > M) return; ans[pos] = 1; dfs(pos + 1, (k * 10 + 1) % n, n); if(flag '' pos > M) return; }
int main() { int n; while(~scanf("%d",&n) && n) { memset(ans, 0, sizeof(ans)); flag = 0; ans[1] = 1; dfs(2, 1 % n, n); for(int i = 1; ~ans[i]; ++i) printf("%d", ans[i]); printf("\n"); } return 0; }
#include<iostream> #include<stdio.h> #include<queue> using namespace std; void bfs(int n) { queue<long long>q; q.push(1); while(!q.empty()) { int i; long long x; x=q.front(); q.pop(); if(x%n==0) { printf("%lld\n",x); return ; } q.push(x*10); q.push(x*10+1); } } int main() { int n; while(scanf("%d",&n)&&n) { bfs(n); } return 0; }
|