Cod sursa(job #1392096)
Utilizator | Data | 18 martie 2015 13:07:41 | |
---|---|---|---|
Problema | GFact | Scor | 50 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 1.34 kb |
#include <cstdio>
#include <cmath>
int p,q;
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=100000000000;
s=1;
long long res=0;
while(s<=e)
{
int nr=0;
long long mij=(s+e)/2;
long long div=p;
while(div<=mij)
{
nr+=mij/div;
div*=p;
}
if(nr>=q)
{
e=mij-1;
res=mij;
}
else s=mij+1;
}
printf("%d\n",res);
}