Pagini recente » Cod sursa (job #101345) | Cod sursa (job #1655275) | Cod sursa (job #1641782) | Cod sursa (job #2242404) | Cod sursa (job #2082708)
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("gfact.in");
ofstream out("gfact.out");
int ndp;
int d[15],p[15];
long long x,y;
long long putere(long long n, int p )
{
long long nr=0;
while (n>=p)
{
nr+=(n/=p);
}
return nr;
}
bool sedivide(long long n)
{
for (int i=0; i<ndp; i++)
{
if(putere(n,d[i])<p[i]*y)
{
return false;
}
}
return true;
}
int main()
{
in>>x>>y;
ndp=0;
int a=2;
while(a*a<=x)
{
if(x%a==0)
{
d[ndp]=a;
while(x%a==0)
{
p[ndp]++;
x/a;
}
ndp++;
}
a++;
}
if(x>1)
{
d[ndp]=x;
p[ndp]=1;
ndp++;
}
long long r,pas;
r=0;
pas=1LL<<45;
while (pas!=0)
{
if(!sedivide(r+pas))
{
r+=pas;
}
pas/=2;
}
r++;
out << r;
in.close();
out.close();
return 0;
}