Pagini recente » Cod sursa (job #2616655) | Cod sursa (job #2539865) | Cod sursa (job #1926111) | Cod sursa (job #33607) | Cod sursa (job #2313220)
#include <bits/stdc++.h>
using namespace std;
ifstream in ("multiplu.in");
ofstream out("multiplu.out");
queue <pair<int,int>> q;
int A,B,C;
bitset <2000005>v;
int get_C()
{
int a=A,b=B,c;
while (b)
{
c=a%b;
a=b;
b=c;
}
return a;
}
stack <int>st;
void output(int loc)
{
while (loc)
{
st.push(loc%2);
loc/=2;
}
while (!st.empty()){out<<st.top();st.pop();}
out<<"\n";
out.close();
in.close();
}
int main()
{int x,loc;
in>>A>>B;
C=(A*B)/get_C();
q.push({1,1});
while (!q.empty())
{
loc=q.front().second;
x=q.front().first;
q.pop();
if (x==0)
{
output(loc);
return 0;
}
if (v[1LL*x*10%C]==0){v[1LL*x*10%C]=1;q.push({1LL*x*10%C,loc*2});}
if (v[(1LL*x*10+1)%C]==0){v[(1LL*x*10+1)%C]=1;q.push({(1LL*x*10+1)%C,loc*2+1});}
}
return 0;
}