Pagini recente » Cod sursa (job #2617851) | Cod sursa (job #541688) | Cod sursa (job #1518873) | Cod sursa (job #1795034) | Cod sursa (job #1608828)
#include <fstream>
using namespace std;
ifstream fin("gfact.in");
ofstream fout("gfact.out");
long long int p,q;
long long int div(long long int n,long long int d)
{
long long int r=0;
while (n>=d)
{
r+=n/d;
n/=d;
}
return r;
}
long long int caut_bin(long long int d,long long int putere)
{
long long int i=0,pas=1<<30;
pas*=pas;
while (pas!=0)
{
if (div(i+pas,d)<putere && i+pas<=d*putere) i+=pas; // !!!
pas/=2;
}
return i+1;
}
int main()
{
long long int d=2,pow=0,max=0,r;
fin>>p>>q;
while (p>1)
{
r=0;
pow=0;
if (d*d>p) d=p;
while (p%d==0) {pow++;p/=d;}
if (pow!=0) r=caut_bin(d,pow*q);
if (r>max) max=r;
d++;
}
fout<<max;
}