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的只包含数字01的倍数
(a+b)%p=(a%p+b%p)%p;
a * b%p=(a%p * b%p)%p;
参照大数取余的思想
char s[1000];int p;
int C(char s[],int p)
{
int len=strlen(s);int ans=0;
for(int i=0;i<len;i++)ans=((ans*10)%p+(s[i]-'0')%p)%p;
return ans;
}
对于6
1%6=1;
l0%6=4;11%6=5;
40%6=4;41%6=5;50%6=2;51%6=3;
40%6=4;41%6=5;50%6=2;51%6=3;20%6=2;21%6=3;30%6=0(出现0,终止)
所以为1110;
int m[10000000];
int n;
int main()
{
while(~scanf("%d",&n)&&n)
{
m[1]=1;
int f=-1;
for(int i=2;;i++)
{
m[i]=(m[i/2]*10+i%2)%n;
if(m[i]==0)
{
f=i;
break;
}
}
int cnt=0;
while(f>0)
{
m[cnt++]=f%2;
f=f/2;
}
for(int i=cnt-1;i>=0;i--)printf("%d",m[i]);
printf("\n");
}
return 0;
}