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 }

 

posted @ 2020-11-04 18:38  BlackSnow  阅读(81)  评论(0)    收藏  举报