Find the multiple
| Time Limit: 1000MS |
|
Memory Limit: 10000K |
| Total Submissions: 22576 |
|
Accepted: 9291 |
|
Special Judge |
Description
Given a positive integer n, write a program to find out a nonzero multiple m of n whose decimal representation contains on Ly 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
26190
Sample Output
10100100100100100100111111111111111111
The main idea: to find a multiple of n, and this number is only composed of 0 1.
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <algorithm>5 using namespacestd;6 intN;7 BOOLFlag;8UnsignedLong Longm;9 voidDFS (unsignedLong LongXintk)Ten { Onecout<<x<<Endl; A if(flag) - return; - if(x%n==0) the { -flag=1; -m=x; - return; + } - if(k== +) + return; ADFS (x*Ten,++k); atDFS (x*Ten+1, k); - return; - } - intMain () - { - inti,j; in while(cin>>n&&N) - { toflag=0; +Dfs1,1); -cout<<m<<Endl; the } *}
POJ Find The multiple 1426 (search)