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.

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

 

题目的意思是输入一个 n , 然后找一个由0 和 1组成的十进制数是 n 的 整倍数  , 

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <queue>
#define Swap(a,b) a ^= b ^= a ^= b
using namespace std ;
const int MAX = 1e7+10;
const int inf = 0xffffff;
typedef long long LL;
void bfs(int n )
{
// bfs 超时了
queue<LL> q ;
q.push(1) ;
while(!q.empty())
{
int i ;
LL x;
x = q.front() ;
q.pop() ;
if(x %n ==0)
{
printf("%lld\n",x);
return ;
}
q.push(x*10) ;
q.push(x*10+1) ;
}
}
bool flag ;
int n ;
void DFS(int cur , LL num )
{
if(cur ==19 || flag)
{
return ;
}
if(num %n == 0)
{
cout<<num <<endl;
flag = 1 ; // 找到做标记
return ;
}
DFS(cur+1, num*10) ;
DFS(cur+1, num*10+1) ;
return ;
}
int main()
{


while(scanf("%d",&n)&&n)
{
flag = 0 ;
DFS(0,1);
}

return 0 ;
}