Pagini recente » Cod sursa (job #3190287) | Cod sursa (job #1235453) | Cod sursa (job #1521167) | Cod sursa (job #867254) | Cod sursa (job #1392126)
#include <cstdio>
#include <cmath>
int p,q;
unsigned long long s,e;
int main()
{
freopen ("gfact.in","r",stdin);
freopen ("gfact.out","w",stdout);
scanf("%d%d",&p,&q);
int exp=1,cat=0;
int st=(int)sqrt(p)+1;
if(p%2==0)
{
exp=2;
while(p%2==0)
{
cat++;
p/=2;
}
}
for(int j=3;j<=st;j+=2)
{
if(p%j==0)
{
exp=j;
cat=0;
while(p%j==0)
{
cat++;
p/=j;
}
}
}
if(p!=1)
{
exp=p;
cat=1;
}
q*=cat;
p=exp;
e=(unsigned long long)p*q+10;
s=1;
unsigned long long res=0;
while(s<=e)
{
unsigned long long nr=0;
unsigned long long mij=(s+e)/2;
unsigned long long div=p;
while(div<=mij)
{
nr+=(unsigned long long) mij/div;
div*=p;
}
if(nr>=q)
{
e=mij-1;
res=mij;
}
else s=mij+1;
}
printf("%llu\n",res);
}