From
Find the multiple
Time Limit: 1000MS |
|
Memory Limit: 10000K |
Total Submissions: 38108 |
|
Accepted: 15916 |
|
Special Judge |
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 this n is not greater than and there are a corresponding m containing no more than 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 digits. If There is multiple solutions for a given value of N, any one of the them is acceptable.
Sample Input
2
6
0
Sample Output
Ten
100100100100100100
111111111111111111
Source Dhaka 2002
Test instructions: Give you a number, ask to find a number is its multiple, and the decimal form of this number is composed of 0 and a
The following: BFs two fork tree. The scope of the answer is within Longlong and can be directly BFS
*poj to be handed in g++.
*BFS can not use while (!q.empty), to use while (1)
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <queue>
#include <map>
using namespace std;
typedef long long LL;
ll BFs (ll N) {
queue<ll>q;
Q.push (1);
while (1) {
LL t=q.front ();
Q.pop ();
if (t%n==0) return t;
Q.push (t*10);
Q.push (t*10+1);
}
}
int main () {
LL n;
while (scanf ("%lld", &n)!=eof&&n) {
printf ("%lld\n", BFS (n));
}
}