Pagini recente » Cod sursa (job #1193897) | Cod sursa (job #145165) | Cod sursa (job #1478615) | Cod sursa (job #2418794) | Cod sursa (job #1301841)
#include <fstream>
#include <cstdio>
#define pmax 2000005
using namespace std;
ifstream f("multiplu.in");
ofstream g("multiplu.out");
int c[pmax];
int r[pmax];
int cnt[pmax];
int n,a,b,mod1,mod2,t;
int sol[100],nr,p,u;
int cmmdc(int a,int b)
{
while (b!=0){
int r=a%b;
a=b;
b=r;
}
return a;
}
int main()
{
int i,j;
f>>a>>b;
n=(a/(cmmdc(a,b)))*b;
p=1;u=1;
c[1]=1;
cnt[1]=1;
while (p<=u){
mod1=(c[p]*10)%n;
mod2=(c[p]*10+1)%n;
if (cnt[mod1]==0) {
c[++u]=mod1;
cnt[mod1]=u;
r[u]=p*10;
}
if (cnt[mod2]==0) {
c[++u]=mod2;
cnt[mod2]=u;
r[u]=p*10+1;
}
p++;
}
t=cnt[0];
while (t>=2)
{
sol[++nr]=r[t]%10;
t=r[t]/10;
}
sol[++nr]=1;
for (i=nr;i>=1;i--)
g<<sol[i];
return 0;
}