Pagini recente » Cod sursa (job #291540) | Cod sursa (job #953356) | Cod sursa (job #3176548) | Cod sursa (job #2203003) | Cod sursa (job #3236643)
#include <fstream>
#include <algorithm>
#include <queue>
#include <stack>
#pragma GCC optimize("O1")
#pragma GCC optimize("O2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
ifstream cin("multiplu.in");
ofstream cout("multiplu.out");
int n,m,k;
pair<int,int>pre[2000002];
queue<pair<int,int>>q;
stack<int>st;
bool v[2000002];
int v2[2000002];
int main()
{
cin>>n>>m;
k=n*m;
int e=__gcd(n,m);
k/=e;
if(k==1){
cout<<1;
return 0;
}
q.push({1,1});
v2[1]=1;
int last=-1;
while(!q.empty())
{
int x=q.front().first,t=q.front().second;
q.pop();
int z=x*10,y=x*10+1;
z%=k,y%=k;
if(v[z]==0)
q.push({z,0}),pre[z].first=x,pre[z].second=t,v[z]=1,v2[z]=0;
if(z==0)
{
last=0;
break;
}
if(v[y]==0)
q.push({y,1}),pre[y].first=x,pre[y].second=t,v[y]=1,v2[y]=1;
if(y==0)
{
last=1;
break;
}
}
while(!q.empty())
q.pop();
//cout<<pre[1].first;
st.push(0);
while(pre[st.top()].first!=0)
st.push(pre[st.top()].first);
while(!st.empty())
cout<<v2[st.top()],st.pop();
return 0;
}