Pagini recente » Cod sursa (job #1064631) | Cod sursa (job #1585720) | Cod sursa (job #836697) | Cod sursa (job #1129534) | Cod sursa (job #2785994)
#include <bits/stdc++.h>
using namespace std;
ifstream in("multiplu.in");
ofstream out("multiplu.out");
const int lim=2e6+13;
const int lim2=3.5e6+13;
bool dp[lim];
int last[lim];
int p[lim2];
int a,b,c;
int main()
{
vector<int> atinse,urm;
ios_base::sync_with_stdio(false);
in.tie(0),out.tie(0);
in>>a>>b;
c=(a*b)/__gcd(a,b);
int e2=0,e5=0;
int cc=c;
while(cc%2==0)
++e2,cc/=2;
while(cc%5==0)
++e5,cc/=5;
if(cc==1)
out<<1;
else
{
p[0]=1;
dp[1]=true;
last[1]=0;
atinse.clear();
atinse.push_back(1);
bool stop=false;
for(int i=1;;++i)
{
urm.clear();
p[i]=(p[i-1]*10)%cc;
for(int x:atinse)
if((x+p[i])%cc==0)
{
dp[0]=true;
last[0]=i;
stop=true;
break;
}
else
{
int y=(x+p[i])%cc;
if(dp[y]==false)
{
urm.push_back(y);
dp[y]=true;
last[y]=i;
}
}
for(int x:urm)
atinse.push_back(x);
if(stop)
break;
}
for(int i=last[0],r=0,j=last[0];j>=0;--j)
{
if(i==j)
{
out<<1;
r=(r-p[i]+cc)%cc;
i=last[r];
}
else out<<0;
}
}
for(int i=1;i<=max(e2,e5);++i)
out<<'0';
out<<'\n';
return 0;
}