浏览器标题切换
浏览器标题切换end

POJ1426-Find The Multiple-bfs

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.

Input

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.

Output

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.

Sample Input

2
6
19
0

Sample Output

10
100100100100100100
111111111111111111

题意:找到只由0或1组成的小于100位的数能够整除题目给出的数据
 1 #include<iostream>
 2 #include<queue>
 3 using namespace std;
 4 
 5 int n;
 6 void bfs(int x)
 7 {
 8 
 9     queue<long long>Q;
10     long long p=1;
11     Q.push(p);
12     while(!Q.empty())
13     {
14         p=Q.front();
15         Q.pop();
16         if(p%n==0)
17         {
18             cout<<p<<endl;
19             break;
20         }
21         Q.push(p*10);
22         Q.push(p*10+1);
23     }
24     return ;
25 }
26 
27 
28 
29 int main()
30 {
31     std::ios::sync_with_stdio(false);
32     while(cin>>n)
33     {
34         if(n==0)
35             break;
36         else
37         {
38             bfs(n);
39         }
40     }
41     return 0;
42 }
View Code

 

posted @ 2019-07-17 23:34  抓水母的派大星  阅读(205)  评论(0编辑  收藏  举报