Pagini recente » Cod sursa (job #1388424) | Cod sursa (job #2253607) | Cod sursa (job #731769) | Cod sursa (job #492644) | Cod sursa (job #2088114)
#include <fstream>
#include <cmath>
using namespace std;
ifstream in("gfact.in");
ofstream out("gfact.out");
const long long N = 1000000000;
long long p, q, c;
long long dp[N], e[N], ndp;
long long nrP(int x, int y)
{
long long rez = 0;
while(x >= y)
{
rez += x /= y;
x /= y;
}
return rez;
}
bool sedivide(int x)
{
for(int i = 0; i < ndp; i++)
{
if(nrP(x, dp[i]) < e[i] * q)
return false;
}
return true;
}
void ep()
{
int d = 2;
while(d * d <= p)
{
if(!p % d)
{
dp[ndp] = d;
int c = 0;
while(p % d)
{
p /= d;
c++;
}
e[ndp] = p;
ndp++;
}
d++;
}
if(p != 1)
{
dp[ndp] = p;
e[ndp] = 1;
ndp++;
}
}
int main()
{
long long b = 0;
in >> p >> q;
long long pas = 1 << 28;
ep();
while(pas)
{
if(!sedivide(b + pas))
{
b += pas;
}
pas /= 2;
}
b++;
out << b << '\n';
return 0;
}