Pagini recente » Cod sursa (job #1978138) | Cod sursa (job #710511) | Cod sursa (job #1572862) | Cod sursa (job #2383683) | Cod sursa (job #3226534)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("gfact.in");
ofstream fout("gfact.out");
int p, q, d ,e;
long long fast_expo(int b, int expo)
{
long long a=b, p=1;
for(;expo;expo>>=1)
{
if(expo&1) p*=a;
a*=a;
}
return p;
}
long long legendre(long long n)
{
long long numitor=d, s=0;
while(numitor<=n)
{
s+=n/numitor;
numitor*=d;
}
return s;
}
long long cautare_binare()
{
long long st=1, dr=d*q*e, med, last=0;
while(st<=dr)
{
med=(st+dr)/2;
if(legendre(med)>=q)
{
last=med;
dr=med-1;
}
else
st=med+1;
}
return last;
}
void max_fact_prim()
{
int n=p, dd=2, ee;
d=e=1;
while(n>1)
{
ee=0;
while(n%dd==0)
{
ee++;
n/=dd;
}
if(ee>0)
{
d=dd;
e=ee;
}
dd++;
if(dd*dd>=n)
dd=n;
}
}
int main()
{
fin >> p >> q;
max_fact_prim();
fout << cautare_binare();
return 0;
}