Cod sursa(job #315635)
#include<stdio.h>
const int NM=2000000;
int coada[NM],pred[NM],val[NM],a,b,m;
int multiplu(int a, int b)
{
int a1=a,b1=b,r=a1%b1;
while(r)
{
a1=b1;
b1=r;
r=a1%b1;
}
return a*b/b1;
}
void citire()
{
freopen("multiplu.in","r",stdin);
freopen("multiplu.out","w",stdout);
scanf("%d%d", &a, &b);
m=multiplu(a,b);
}
void calcul()
{
int u=1,p=0;
coada[0]=1;
val[1]=1;
pred[1]=0;
while(!val[0] && !pred[0])
{
if(!val[(coada[p]*10)%m] && !pred[(coada[p]*10)%m])
{
coada[u]=(coada[p]*10)%m;
val[coada[u]]=0;
pred[coada[u++]]=coada[p];
}
if(!val[(coada[p]*10+1)%m] && !pred[(coada[p]*10+1)%m])
{
coada[u]=(coada[p]*10+1)%m;
val[coada[u]]=1;
pred[coada[u++]]=coada[p];
}
p++;
}
}
void afisare(int x)
{
if(pred[x])
afisare(pred[x]);
printf("%d",val[x]);
}
int main()
{
citire();
calcul();
afisare(0);
return 0;
}