Pagini recente » Cod sursa (job #480201) | Cod sursa (job #2195047) | Cod sursa (job #1127379) | Cod sursa (job #2879850) | Cod sursa (job #2651899)
#include <fstream>
#include <queue>
using namespace std;
ifstream in("multiplu.in");
ofstream out("multiplu.out");
const int N=2000000;
queue<long> q;
pair<long, long> rest[N+1];
bool nr[101];
bool drum[N];
int main()
{
int a,b,r,ca,cb;
long long m;
in>>a>>b;
ca=a;
cb=b;
while(b!=0)
{
r=a%b;
a=b;
b=r;
}
m=ca*cb/a;
q.push(1);
rest[1].first=0;
rest[1].second=1;
drum[1]=1;
a=-1;
while(!q.empty() && a!=0)
{
int prim = q.front();
q.pop();
a=(prim*10)%m;
if (!drum[a])
{
q.push(a);
rest[a].first = prim;
rest[a].second = 0;
drum[a]=1;
}
if (a == 0)
{
break;
}
a=(prim*10+1)%m;
if(!drum[a])
{
q.push(a);
rest[a].first=prim;
rest[a].second=1;
drum[a]=1;
}
}
int cnt=0;
while(rest[a].first!=0)
{
nr[cnt++]=rest[a].second;
a=rest[a].first;
}
nr[cnt]=1;
for(int i=cnt; i>=0; i--)
{
out<<nr[i];
}
return 0;
}