Pagini recente » Cod sursa (job #747584) | Cod sursa (job #1867898) | Cod sursa (job #1296332) | Cod sursa (job #273071) | Cod sursa (job #2284009)
#include <cstdio>
#include <cstring>
using namespace std;
const int NMAX=2000000;
bool f[NMAX+5];
struct multiplu
{
bool c;
int r,t;
};
multiplu q[NMAX+5];
int cmmmc(int a,int b)
{
int r,ca=a,cb=b,m;
while(b)
{
r=a%b;
a=b;
b=r;
}
m=(ca*cb)/a;
return m;
}
int main()
{
freopen("multiplu.in","r",stdin);
freopen("multiplu.out","w",stdout);
int a,b,p=1,u=1,r1,cnt=0,m,i;
bool ok=0;
multiplu temp;
scanf("%d%d",&a,&b);
m=cmmmc(a,b);
temp.c=1;
temp.r=1;
temp.t=0;
q[1]=temp;
while(p<=u && !ok)
{
r1=(q[p].r*10+0)%m;
if(!f[r1])
{
f[r1]=1;
temp.c=0;
temp.r=r1;
temp.t=p;
q[++u]=temp;
if(r1==0)
{
ok=1;
continue;
}
}
r1=(q[p].r*10+1)%m;
if(!f[r1])
{
f[r1]=1;
temp.c=1;
temp.r=r1;
temp.t=p;
q[++u]=temp;
if(r1==0)
{
ok=1;
continue;
}
}
p++;
}
memset(f,0,sizeof(f));
while(u!=0)
{
f[++cnt]=q[u].c;
u=q[u].t;
}
for(i=cnt;i>=1;i--)
printf("%d",f[i]);
return 0;
}