Pagini recente » Cod sursa (job #1995773) | Cod sursa (job #1224186) | Cod sursa (job #1831894) | Cod sursa (job #2182815) | Cod sursa (job #1273870)
#include <fstream>
#define NMax 2000001
using namespace std;
ifstream f("multiplu.in");
ofstream g("multiplu.out");
int a, b, cmmmc, i, qu[NMax], sol, p, u, lta, nr[100];
int fath[NMax], uc[NMax], fr[NMax];
int cmmdc(int x, int y)
{
int r=0;
while (y!=0) {
r=x%y;
x=y;
y=r;
}
return x;
}
int main()
{
f>>a>>b;
int cmmmc=a*b/cmmdc(a,b);
qu[1]=1;
fath[1]=0;
uc[1]=1;
sol=1;
p=1;
u=1;
int ok=1;
while (ok==1) {
if ((qu[p]*10)%cmmmc == 0) {
lta=p;
ok=0;
}
else {
if (!fr[(qu[p]*10)%cmmmc]) {
qu[++u]=(qu[p]*10)%cmmmc;
fath[u]=p;
fr[(qu[p]*10)%cmmmc]=1;
}
}
if ((qu[p]*10+1)%cmmmc == 0) {
lta=p;
nr[1]=1;
ok=0;
}
else {
if (!fr[(qu[p]*10+1)%cmmmc]) {
qu[++u]=(qu[p]*10+1)%cmmmc;
fath[u]=p;
uc[u]=1;
fr[(qu[p]*10+1)%cmmmc]=1;
}
}
p++;
}
int ind=1;
while (lta!=0) {
nr[++ind]=uc[lta];
lta=fath[lta];
}
for (i=ind; i>=1; i--)
g<<nr[i];
return 0;
}