Pagini recente » Cod sursa (job #2726995) | Cod sursa (job #813162) | Cod sursa (job #3276857) | Cod sursa (job #1995935) | Cod sursa (job #2490730)
#include <bits/stdc++.h>
using namespace std;
ifstream f ("multiplu.in");
ofstream g ("multiplu.out");
int a , b;
bitset < 200005 > mark;
queue < vector < short > > c;
vector < short > d , nr;
int cmmdc(int a , int b)
{
int r;
while(b)
{
r = a % b;
a = b;
b = r;
}
return a;
}
int Divide(vector < short > a , int x)
{
int r = 0 , i;
for(i = a[0] ; i >= 1 ; i--)
{
r = r * 10 + a[i];
r = r % x;
}
return r;
}
void Debug(vector < short > a)
{
for(int i = a[0] ; i >= 1 ; i--)
cout << a[i];
cout << endl;
}
int main()
{
f >> a >> b;
int m = a * b / cmmdc(a , b) , r;
mark[1] = 1;
d.push_back(1);
d.push_back(1);
c.push(d);
while(!c.empty())
{
d = c.front();
c.pop();
++d[0];
d.push_back(0);
nr = d;
reverse(nr.begin() + 1 , nr.end());
r = Divide(nr , m);
if(r == 0)
{
for(int i = nr[0] ; i >= 1 ; i--)
g << nr[i];
return 0;
}
// Debug(nr);
if(!mark[r])
c.push(d) , mark[r] = 1;
d[d[0]] = 1;
nr[1] = 1;
r = Divide(nr , m);
if(r == 0)
{
for(int i = nr[0] ; i >= 1 ; i--)
g << nr[i];
return 0;
}
// Debug(nr);
if(!mark[r])
c.push(d) , mark[r] = 1;
}
return 0;
}