【题解】POJ-1426 Find The Multiple

Find The Multiple (POJ - 1426)

题面

Given a positive integer n, write a program to find out a nonzero multiple m of n whose decimal representation contains only the digits 0 and 1. You may assume that n is not greater than 200 and there is a corresponding m containing no more than 100 decimal digits.

输入

The input file may contain multiple test cases. Each line contains a value of n (1 <= n <= 200). A line containing a zero terminates the input.

输出

For each value of n in the input print a line containing the corresponding value of m. The decimal representation of m must not contain more than 100 digits. If there are multiple solutions for a given value of n, any one of them is acceptable.

样例输入

1
2
3
4
2
6
19
0

样例输出

1
2
3
10
100100100100100100
111111111111111111

提示

思路

一维bfs

代码

查看代码
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
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int N = 15+5;

int n;

void bfs() {
queue<ll> q;
q.push(1);
while(!q.empty()) {
ll t = q.front();
q.pop();
if(t%n==0) {
printf("%lld\n", t);
return ;
}
q.push(t*10);
q.push(t*10+1);
}
}

int main(void) {

while(scanf("%d", &n)==1 && n) {
bfs();
}
return 0;
}
_/_/_/_/_/ EOF _/_/_/_/_/