Pagini recente » Cod sursa (job #613148) | Cod sursa (job #57271) | Cod sursa (job #178971) | Cod sursa (job #521105) | Cod sursa (job #2322048)
#include <fstream>
#include <queue>
using namespace std;
ifstream cin("multiplu.in");
ofstream cout("multiplu.out");
struct chestie{
bool val[510];
int r,sz;
}mp,mp0,mp1,v;
int A,B,C,sol[510];
bool bif[2000010];
queue <chestie> q;
int cmmmc(int x,int y);
void becky();
int main()
{
cin>>A>>B;
C=cmmmc(A,B);
v.sz=v.val[1]=1;
v.r=1;
q.push(v);
becky();
for(int i=1;i<=sol[0];i++)
cout<<sol[i];
cout<<'\n';
return 0;
}
void becky()
{
if(!q.empty())
{
mp=q.front();
q.pop();
if(mp.r==0)
{
for(int i=mp.sz;i>0;i--)
sol[i]=mp.val[i];
bif[0]=0;sol[0]=mp.sz;
return;
}
else{
mp1.r=(mp.r*10+1)%C;
mp0.r=(mp.r*10)%C;
if(!bif[mp1.r])
{
mp1.sz=mp.sz+1;
for(int i=1;i<mp1.sz;i++)
mp1.val[i]=mp.val[i];
mp1.val[mp1.sz]=1;bif[mp1.r]=1;
q.push(mp1);
}
if(!bif[mp0.r])
{
mp0.sz=mp.sz+1;
for(int i=1;i<mp0.sz;i++)
mp0.val[i]=mp.val[i];
mp0.val[mp0.sz]=0;bif[mp0.r]=1;
q.push(mp0);
}
becky();
}
}
}
int cmmmc(int x,int y)
{
int r=x%y,p=x*y;
while(r)
{
x=y;
y=r;
r=x%y;
}
return p/y;
}