Pagini recente » Cod sursa (job #560325) | Cod sursa (job #2654017) | Cod sursa (job #2242782) | Cod sursa (job #1392422) | Cod sursa (job #3278381)
#include <fstream>
#include <queue>
#include <vector>
#include <iostream>
using namespace std;
const int M = 2e6;
int cmmdc(int a, int b)
{
while (b != 0)
{
int r = a % b;
a = b;
b = r;
}
return a;
}
int cmmmc(int a, int b)
{
return a * b / cmmdc(a, b);
}
void refac_numarul(int x, vector <pair <int, int>> &pred, ofstream &out)
{
if (x == 1)
{
out << 1;
return;
}
refac_numarul(pred[x].first, pred, out);
out << pred[x].second;
}
int main()
{
ifstream in("multiplu.in");
ofstream out("multiplu.out");
int a, b;
in >> a >> b;
int m = cmmmc(a, b);
vector < pair <int, int>> pred(m, {-1, -1});
queue <int> q;
q.push(1);
pred[1].first = 0;
pred[1].second = -1;
while (!q.empty())
{
int x = q.front();
q.pop();
int y = x * 10 % m;
if (pred[y].first == -1)
{
q.push(y);
pred[y].first = x;
pred[y].second = 0;
}
y = (x * 10 + 1) % m;
if (pred[y].first == -1)
{
q.push(y);
pred[y].first = x;
pred[y].second = 1;
}
}
refac_numarul(0, pred, out);
in.close();
out.close();
return 0;
}