Pagini recente » Cod sursa (job #3255165) | Cod sursa (job #48801) | Cod sursa (job #1514423) | Cod sursa (job #477906) | Cod sursa (job #2718386)
#include <fstream>
#include <bitset>
#include <queue>
using namespace std;
ifstream in("multiplu.in");
ofstream out("multiplu.out");
const int N = 2e6 + 1;
int pred[N];
bitset <N> ultim;
void M(int n)
{
if(n == -1) return;
M(pred[n]);
out << ultim[n];
}
int cmmdc(int a, int b)
{
while(b)
{
int r = a % b;
a = b;
b = r;
}
return a;
}
int cmmmc(int a, int b)
{
return a / cmmdc(a,b) * b;
}
void bfs(int m)
{
queue <int> q;
q.push(1);
pred[1] = -1;
ultim[1] = 1;
while(!q.empty())
{
int x = q.front();
q.pop();
for(int i=0; i<2; i++)
{
int y = (x*10 + i) % m;
if(pred[y] == 0)
{
ultim[y] = i;
pred[y] = x;
if(y == 0) return;
q.push(y);
}
}
}
}
int main()
{
int a, b, m;
in >> a >> b;
m = cmmmc(a, b);
bfs(m);
M(0);
return 0;
}