Pagini recente » Cod sursa (job #322598) | Cod sursa (job #1743982) | Cod sursa (job #441325) | Cod sursa (job #2235872) | Cod sursa (job #1726250)
#include <bits/stdc++.h>
using namespace std;
bitset<2000005>cif;
bitset<2000005>viz;
int pred[2000005],q[2000005],C;
int cmmmc(int a,int b)
{
int r,x,y;
x=a;
y=b;
while(b!=0)
{
r=a%b;
a=b;
b=r;
}
return (x*y)/a;
}
void Rezolva()
{
ofstream fout("multiplu.out");
int pr,ul,k,x,y;
pr=ul=1;
q[ul]=1;
pred[1]=0;
cif[1]=1;
k=1;
viz[1]=1;
while(viz[0]==0)
{
x=q[pr];
y=(x*10)%C;
if(viz[y]==0)
{
viz[y]=1;
q[++ul]=y;
cif[++k]=0;
pred[k]=pr;
}
if(viz[0]==0)
{
y=(x*10+1)%C;
if(viz[y]==0)
{
viz[y]=1;
q[++ul]=y;
cif[++k]=1;
pred[k]=pr;
}
}
pr++;
}
stack<int>st;
while(ul>0)
{
st.push(cif[ul]);
ul=pred[ul];
}
while(!st.empty())
{
fout<<st.top();
st.pop();
}
}
int main()
{
int a,b;
ifstream fin("multiplu.in");
fin>>a>>b;
C=cmmmc(a,b);
Rezolva();
return 0;
}