1. 程式人生 > 實用技巧 >D - Find The Multiple(2)

D - Find The Multiple(2)

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
 1 #include<iostream>
 2 #include<cstdio>
 3 using namespace std;
 4 typedef long long ll;
 5 int flag;//標誌變數
 6 int n;//數字位數
 7 void dfs(int dig,ll m)
 8 {
 9     if(dig>19||flag)//在n<=200的範圍內,n的倍數位數最大是19
10         return;
11     if(m%n==0
)//可以整除 12 { 13 flag=1;//找到解 14 cout<<m<<endl; 15 return; 16 } 17 else//沒找到 18 { 19 dig++;//對資料位數進行增加,再遞迴 20 dfs(dig,m*10);//分別遍歷兩種不一樣的尾數的情況 21 dfs(dig,m*10+1); 22 } 23 } 24 int main() 25 { 26 int dig; 27 while(~scanf("%d",&n)&&n!=0
) 28 { 29 dig=1;//位數最少為1 30 flag=0;//重置變數 31 dfs(dig,1); 32 } 33 return 0; 34 }