Pagini recente » Cod sursa (job #193751) | Cod sursa (job #1853536) | Cod sursa (job #2453806) | Cod sursa (job #1323049) | Cod sursa (job #2940993)
#include <iostream>
#include <fstream>
#include<queue>
using namespace std;
ifstream fin("multiplu.in");
ofstream fout("multiplu.out");
const int Nmax=2000005;
int a,b,n;
queue<int> q;
int prv[Nmax];
bool visited[Nmax];
int cmmdc(int a,int b)
{
int r=a%b;
while(r>0)
{
a=b;
b=r;
r=a%b;
}
return b;
}
void reconst(int rest)
{
if(rest==1)
{
fout<<1;
return;
}
reconst(prv[rest]);
if(prv[rest]*10%n==rest)
{
fout<<0;
}
else
{
fout<<1;
}
}
int main()
{
fin>>a>>b;
n=a*b/cmmdc(a,b);
q.push(1);
visited[1]=true;
if(n==1)
{
fout<<n;
return 0;
}
while(!q.empty())
{
int rest=q.front();
q.pop();
int next_rest = (rest*10)%n;
if(!visited[next_rest])
{
q.push(next_rest);
visited[next_rest] =true;
prv[next_rest]=rest;
}
if(next_rest==0)
{
break;
}
next_rest = (rest*10+1)%n;
if(!visited[next_rest])
{
q.push(next_rest);
visited[next_rest]=true;
prv[next_rest]=rest;
}
if(next_rest==0)
{
break;
}
}
reconst(0);
return 0;
}