poj 1426 Find The Multiple

Description

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
题目意思看懂后不敢动手,因为题目说了m最大位数少于100,以为是属于大数范畴,迟迟不敢动手,后来看了别人的解题报告,试写了一个bfs代码,用G++交了,并且过了。注意用C++交的话最好不要用STL里面的
queue,还是自己用数组模拟队列吧。
要是这一题没放在bfs里面,真的不知道怎么动手了……

 1 #include <iostream>
 2 #include <queue>
 3 
 4 using namespace std;
 5 int n;
 6 long long  bfs()
 7 {
 8     queue<long long>q;
 9     while(!q.empty())
10     {
11         q.pop();
12     }
13     q.push(1);
14     while(1)
15     {
16         long long  p=q.front();
17         if(p%n==0)
18         return p;
19         q.pop();
20         q.push(p*10);
21         q.push(p*10+1);
22     }
23 }
24 int main()
25 {
26     while(cin>>n && n)
27     {
28         long long res=bfs();
29         cout<<res<<endl;
30     }
31     return 0;
32 }
View Code
原文地址:https://www.cnblogs.com/ouyangduoduo/p/3110540.html