Pagini recente » Cod sursa (job #577988) | Cod sursa (job #1252217) | Cod sursa (job #1110647) | Cod sursa (job #1415680)
#include<cstdio>
bool resturi[2000001];
char numar[50];
struct element{int cifra,poz,rest;};
element coada[2000001];
int main()
{
freopen("multiplu.in","r",stdin);
freopen("multiplu.out","w",stdout);
int a,b;
scanf("%d %d ",&a,&b);
int r,cmmdc=a,a1=a,b1=b;
while(b)
{
r=cmmdc%b;
cmmdc=b;
b=r;
}
int cmmmc=a1*b1/cmmdc;
resturi[1]=true;
coada[1].cifra=1;
coada[1].rest=1;
coada[1].poz=0;
int in=1;
int sf=1,poz;
bool gasit=false;
while(!gasit)
{
for(int i=0;i<=1;i++)
{
if(resturi[(coada[in].rest*10+i)%cmmmc]!=true)
{
coada[++sf].cifra=i;
coada[sf].poz=in;
coada[sf].rest=(coada[in].rest*10+i)%cmmmc;
if(coada[sf].rest==0)
{
gasit=true;
poz=sf;
}
resturi[coada[sf].rest]=true;
}
}
in++;
}
int next=poz,el=0;
while(coada[next].poz!=0)
{
numar[++el]=coada[next].cifra;
next=coada[next].poz;
}
numar[++el]=coada[next].cifra;
for(int i=el;i>=1;i--)
printf("%d",numar[i]);
return 0;
}