Pagini recente » Statistici Ivanoiu George Stefan (IvanoiuStefan97) | Istoria paginii runda/oni2011_9 | Cod sursa (job #2671006) | Cod sursa (job #1268542) | Cod sursa (job #334474)
Cod sursa(job #334474)
#include <stdio.h>
#define N 2000005
#define P 1<<18
int a,b,m,r,pozitie;
char marc[N];
char cif[N];
int din[N];
char sol[P];
int cmmdc(int x,int y)
{
int r=x%y;
while(r)
{
x=y;
y=r;
r=x%y;
}
return y;
}
int cmmmc(int a,int b)
{
return (int)((long long)a*b/cmmdc(a,b));
}
int mod(int A[], int B)
{
int i, t = 0;
for (i = 1; i <=A[0]; i++)
t = (t * 10 + A[i]) % B;
return t;
}
void solve()
{
marc[1]=1;
cif[1]=1;
int i,t;
while (marc[0]==0)
{
for (i=1; i<=m-1; i++)
if (marc[i])
{
t=(i*10)%m;
if (marc[t]==0)
{
marc[t]=1;
din[t]=i;
cif[t]=0;
}
t=(t+1)%m;
if (marc[t]==0)
{
marc[t]=1;
din[t]=i;
cif[t]=1;
}
}
}
pozitie=0;
while (pozitie!=1)
{
sol[++r]=cif[pozitie];
pozitie=din[pozitie];
}
sol[++r]=1;
for (i=r; i>=1; i--)
printf("%d",sol[i]);
}
int main()
{
freopen("multiplu.in","r",stdin);
freopen("multiplu.out","w",stdout);
scanf("%d%d",&a,&b);
m=cmmmc(a,b);
solve();
return 0;
}