Pagini recente » Cod sursa (job #387932) | Cod sursa (job #1909750) | Cod sursa (job #2411323) | Cod sursa (job #549602) | Cod sursa (job #2965792)
#include <fstream>
#include <vector>
#include <queue>
using namespace std;
ifstream cin("multiplu.in");
ofstream cout("multiplu.out");
const int NMAX = 2e6;
const long long inf = 2e18;
queue <long long> q;
long long min_num[NMAX + 1], cmmmc;
int cmmdc(int x, int y){
int r = 0;
while(y){
r = x % y;
x = y;
y = r;
}
return x;
}
void bfs(int x){
q.push(x);
while(!q.empty()){
long long x = q.front();
q.pop();
// ma duc fie in rest r, fie in rest r + 1
int rm = x % cmmmc;
if(rm == 0)
return;
rm *= 10;
rm %= cmmmc;
if(min_num[rm] == inf){
min_num[rm] = x * 10;
q.push(x * 10);
}
rm = rm * 10 + 1;
rm %= cmmmc;
if(min_num[rm] == inf){
min_num[rm] = x * 10 + 1;
q.push(x * 10 + 1);
}
}
}
int main(){
long long x = 0, y = 0;
cin >> x >> y;
cmmmc = x * y / cmmdc(x, y);
for(int i = 0; i < cmmmc; i++)
min_num[i] = inf;
bfs(1);
cout << min_num[0];
}