Pagini recente » Cod sursa (job #809671) | Cod sursa (job #3196307) | Cod sursa (job #3169327) | Cod sursa (job #3254950) | Cod sursa (job #2490737)
#include <bits/stdc++.h>
using namespace std;
ifstream f ("multiplu.in");
ofstream g ("multiplu.out");
int a , b;
bitset < 2000050 > 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 Print_Answer(vector < short > a)
{
for(int i = a[0] ; i >= 1 ; i--)
g << a[i];
exit(0);
}
void Debug(vector < short > a)
{
for(int i = 1 ; i <= a[0] ; i++)
cout << a[i];
cout << endl;
}
int main()
{
ios_base::sync_with_stdio(false);
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)
Print_Answer(nr);
if(!mark[r])
c.push(d) , mark[r] = 1;
d[d[0]] = 1;
nr[1] = 1;
r = Divide(nr , m);
if(r == 0)
Print_Answer(nr);
if(!mark[r])
c.push(d) , mark[r] = 1;
}
return 0;
}