Pagini recente » Cod sursa (job #1054615) | Cod sursa (job #2266372)
#include <bits/stdc++.h>
#define pb push_back
#define DM 2000005
using namespace std;
ifstream fin("multiplu.in");
ofstream fout("multiplu.out");
queue<pair<pair<int,int>,char> >Q;
int lcm,a,b;
bool viz[DM];
int mp[DM];
char rez[DM];
void afis(int pos)
{
if(pos!=1)
afis(mp[pos]);
fout<<rez[pos];
}
int main()
{
fin>>a>>b;
lcm = a*b/__gcd(a,b);
Q.push({{1,1},'1'});
viz[1]=true;
while(!Q.empty()){
int curr = Q.front().first.first;
int where=Q.front().first.second;
char r=Q.front().second;
Q.pop();
rez[curr]=r;
mp[curr]=where;
int R0 = (curr*10)%lcm;
int R1 = (curr*10+1)%lcm;
if(viz[R0]==true) continue;
if(R0==0)
{
rez[0]='0';
mp[0]=curr;
break;
}
viz[R0]=true;
Q.push({{R0,curr},'0'});
if(viz[R1]==true) continue;
if(R1==0)
{
rez[0]='1';
mp[0]=curr;
break;
}
viz[R1]=true;
Q.push({{R1,curr},'1'});
}
afis(0);
return 0;
}