Pagini recente » Cod sursa (job #2948988) | Cod sursa (job #1870954) | Cod sursa (job #65808) | Cod sursa (job #1635335) | Cod sursa (job #2078515)
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
const int M=10000;
pair<int,int> ds[M];
int nd;
bool divid (int x)
{
int i,j,p;
for(i=0; 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");
int p,q,d,pas=1<<30,r=0,x;
fin>>p>>q;
int i,j;
d=2;
x=p;
while(d*d<=x&&p!=1)
{
if(p%d==0)
{
ds[nd].first=d;
while(p%d==0)
{
ds[nd].second++;
p/=d;
}
ds[nd].second*=q;
nd++;
}
d++;
}
if(p!=1)
{
ds[nd].first=p;
ds[nd].second=q;
nd++;
}
nd--;
while(pas!=0)
{
if(!divid(r+pas))
r+=pas;
pas/=2;
}
fout<<r+1;
return 0;
}