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
给你一个n,让你找一个n的倍数,它的每个位不是0就是1。
这次题解用咆哮体写题解!这题是搜索你敢信?这题答案不超过unsigned __int64 你敢信?啊? 啊! 啊?
网络上还有说什么考到同余定理的人?你不知道答案不超unsigned __int64,你敢写?
代码如下:
1 #include<iostream> 2 #include<cstdlib> 3 #include<cstdio> 4 #include<cstring> 5 #include<algorithm> 6 #include<cmath> 7 #include<queue> 8 using namespace std; 9 bool found; 10 int n; 11 void dfs(unsigned __int64 x,int step) 12 { 13 if(found) 14 return ; 15 if(x%n==0) 16 { 17 printf("%I64u ",x); 18 found=true; 19 return ; 20 } 21 if(k==19) 22 return ; 23 dfs(x*10,step+1); 24 dfs(x*10+1,step+1); 25 } 26 int main() 27 { 28 while(cin>>n,n) 29 { 30 found=false; 31 dfs(1,0); 32 } 33 return 0; 34 }
最后提醒下自己写prinf 是老老实实写%I64u...