Cod sursa(job #3152503)
| Utilizator | Data | 25 septembrie 2023 13:20:11 | |
|---|---|---|---|
| Problema | GFact | Scor | 15 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva de probleme | Marime | 0.71 kb |
#include <fstream>
using namespace std;
ifstream cin("gfact.in");
ofstream cout("gfact.out");
int main()
{
long long p,q,d,x,n;
cin>>p>>q;
if(p%2==0)
d=max(p/2,1LL*2);
else
for(d=3;d*d<=p;d+=2)
if(p%d==0)
{
d=max(p/d,d);
break;
}
if(p%d!=0)
d=p;
long long st=1,mij,dr=1000000000000000000;
while(st<dr)
{
mij=(st+dr)/2;
x=1;
n=0;
while(x*d<=mij)
{
x*=d;
n+=mij/x;
}
if(n<q)
st=mij+1;
else
dr=mij-1;
}
cout<<st;
return 0;
}
