Find the multiple
Time limit:1000 ms |
|
Memory limit:10000 K |
Total submissions:18390 |
|
Accepted:7445 |
|
Special Judge |
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 in 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
26190
Sample output
10100100100100100100111111111111111111
Same modulus theorem:
(A * B) % N = (a % N * B % N) % N;
(A + B) % N = (a % N + B % N) % N;
The first 14 digits are: 1, 10, 11, 100, 101, 110, 111, 1000, 1001, 1010, 1011, 1100...
1110% 6 = (110*10 + 0) % 6 = (110% 6) * 10) % 6 + (0% 6 );
MoD [x] = (mod [X/2] * 10 + x % 2) % N;
#include<stdio.h>#define N 600000int mod[N];int ans[200];int main(){ int i,k,n; while(scanf("%d",&n),n) { mod[1]=1%n; for(i=2;mod[i-1]!=0;i++) { mod[i]=(mod[i/2]*10+i%2)%n; } i--; k=0; while(i) { ans[k++]=i%2; i/=2; } for(i=k-1;i>=0;i--) printf("%d",ans[i]); puts(""); } return 0;}
Poj 1426 find the multiple (BFS + same modulus theorem)