Pagini recente » Cod sursa (job #2852750) | Cod sursa (job #2760957) | Cod sursa (job #1655086) | Cod sursa (job #2354018) | Cod sursa (job #115029)
Cod sursa(job #115029)
#include <fstream.h>
long cmmmc(long a,long b)
{ long p,r;
p=a*b;
while (a%b!=0)
{ r=a%b;
a=b;
b=r;
}
return p/b;
}
int verif(long long x)
{ while (x>0)
{ if (((x%10)!=0)&&((x%10)!=1)) return 0;
x=x/10;
}
return 1;
}
int cifra(long long x)
{ int c;
c=x;
while (x>0)
{ c=x;
x=x/10;
}
return c;
}
long long next (long long x)
{ long long y=0,p=1;
while (x>9)
{ y=y+x%10*p;
p=p*10;
x=x/10;
}
return y;
}
long long dif(long long x,long long y)
{ long long d=1;
while (y>0)
{ x=x/10;
y=y/10;
}
while (x>0)
{ d=d*10;
x=x/10;
}
return d;
}
int nrc(long long x)
{ if (x==0) return 1;
int nr=0;
while (x>0)
{ nr++;
x=x/10;
}
return nr;
}
int main()
{ long a,b;
long long x,m,y;
int c,d,nrm,nry,sw;
ifstream f("multiplu.in");
ofstream g("multiplu.out");
f>>a>>b;
m=cmmmc(a,b);
nrm=nrc(m);
d=cifra(m);
x=m;
while (verif(x)==0)
{ x=x+m;
y=x;
nry=nrc(y);
sw=0;
while (nry>=nrm)
{ if (sw==0) c=cifra(y);
if (((c!=1&&c!=0)||sw==1)&&c+d<9)
{ x=x+m*dif(y,m);
sw=1;
}
y=next(y);
nry--;
}
}
g<<x;
f.close();
g.close();
return 0;
}