Pagini recente » Cod sursa (job #2266212) | Cod sursa (job #378678) | Cod sursa (job #366236) | Cod sursa (job #610351) | Cod sursa (job #1068116)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("gfact.in");
ofstream fout("gfact.out");
long long int f(long long int a, long long int pow)
{
long long int k=0;
for(long long int i=a;i<=pow;i*=a)
{
k+=(pow/i);
}
return k;
}
long long int make_sol(long long int a, long long int pow)
{
long long int mid, g;
long long int st=1;
long long int dr=a*pow;
while(st<dr)
{
mid=st+((dr-st)>>1);
g=f(a,mid);
if(g<pow)
st=mid+1;
else if(g>=pow)
dr=mid;
}
return st;
}
int main()
{
long long int a, b, i, l, k, j;
fin>>a>>b;
if(a==1)
{
fout<<"0\n";
return 0;
}
l=0;
if(a%2==0)
{
k=0;
while(a%2==0)
{
a/=2;
k++;
}
j=make_sol(2,k*b);
l=max(l, j);
}
for(i=3;i*i<=a;i+=2)
{
if(a%i==0)
{
k=0;
while(a%i==0)
{
a/=i;
k++;
}
j=make_sol(i,k*b);
l=max(l, j);
}
}
if(a>1)
{
j=make_sol(a,b);
l=max(l, j);
}
fout<<l;
}