Pagini recente » Cod sursa (job #2798658) | Cod sursa (job #1835349) | Monitorul de evaluare | Cod sursa (job #894793) | Cod sursa (job #2078529)
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
const int M=100000;
pair<int,int> ds[M];
int nd;
bool divid (long long x)
{
int i,p;
long long j;
for(i=1; i<=nd ; i++)
{
p=0;
j=ds[i].first;
while(j<=x)
{
p+=(x/j);
j*=ds[i].first;
}
if(p<ds[i].second) return 0;
}
return 1;
}
int main()
{
ifstream fin("gfact.in") ;
ofstream fout("gfact.out");
long long p,q,d,pas=1<<30,r=0,x;
fin>>p>>q;
d=2;
x=p;
while(d*d<=x&&p!=1)
{
if(p%d==0)
{
++nd;
ds[nd].first=d;
while(p%d==0)
{
ds[nd].second++;
p/=d;
}
ds[nd].second*=q;
}
d++;
}
if(p!=1)
{
++nd;
ds[nd].first=p;
ds[nd].second=q;
}
while(pas!=0)
{
if(!divid(r+pas))
r+=pas;
pas/=2;
}
fout<<r+1;
return 0;
}