Pagini recente » Cod sursa (job #1461598) | Cod sursa (job #1854956) | Cod sursa (job #551437) | Cod sursa (job #1288326) | Cod sursa (job #123936)
Cod sursa(job #123936)
//111 101 000 010 010 000 000
// 18 446 744 073 709 551 616
#include <stdio.h>
long rest[2000003];
long A,B,cmmmc,i,p,q,m,x;
char mark[2000003],cif[2000003];
int up[2000003];
void write(int x){
if (up[x]!=-1)
write (up[x]);
printf("%ld",cif[x]);
}
int main(){
freopen("multiplu.in","r",stdin);
freopen("multiplu.out","w",stdout);
scanf("%ld %ld",&A,&B);
cmmmc=A*B;
while (A!=B)
if (A>B){
A=A%B;
if (A==0)A==B;
}
else{
B=B%A;
if (B==0)B=A;
}
cmmmc/=A;
rest[1]=1;up[1]=-1;
mark[1]=1;cif[1]=1;
p=1;q=1;
while (!mark[0]&&q<=2000000){
x=(rest[p]*10)%cmmmc;
if (!mark[x]){
q++;rest[q]=x;
mark[x]=1;
up[q]=p;
cif[q]=0;
if (!x)break;
}
x=(rest[p]*10+1)%cmmmc;
if (!mark[x]){
q++;rest[q]=x;
mark[x]=1;
up[q]=p;
cif[q]=1;
if (!x)break;
}
p++;
//printf("%ld\n",p);
}
write (q);
printf("\n");
return 0;
}