Pagini recente » Cod sursa (job #698789) | Cod sursa (job #2887486) | Rating Mihnea Velin (MihneaVelin) | Cod sursa (job #517271) | Cod sursa (job #2093402)
#include <iostream>
#include <fstream>
#include <cmath>
using namespace std;
int prim(int a){
for(int i=2;i*i<=a;++i){
if(a%i==0)
return 0;
}
return 1;
}
int leg(int a,int p){
int rez=1,q=0;
while(rez*p<=a){
rez*=p;
q+=a/rez;
}
return q;
}
int main()
{
ifstream cin("gfact.in");
ofstream cout("gfact.out");
long long p,q,fact=0,max=0,x=2;
cin>>p>>q;
if(p==1){
cout<<1;
return 0;
}
while(x*x<=p && p>1){
if(p%x==0){
int cnt=0;
while(p%x==0){
cnt++;
p/=x;
}
long long st=1,dr=cnt*x*q,sol;
while(st<=dr){
long long poz=(st+dr)/2;
if(leg(poz,x)>=cnt*q){
sol=poz;
dr=poz-1;
}
else
st=poz+1;
}
if(sol>max)
max=sol;
}
x++;
}
if(p!=1){
long long dr=p*q,st=1,sol;
while(st<=dr){
long long poz=(st+dr)/2;
if(leg(poz,p)>=q){
sol=poz;
dr=poz-1;
}
else
st=poz+1;
}
if(sol>max)
max=sol;
}
cout<<max;
return 0;
}