Pagini recente » Cod sursa (job #1027155) | Cod sursa (job #339168) | Cod sursa (job #1230031) | Cod sursa (job #1254492) | Cod sursa (job #495024)
Cod sursa(job #495024)
#include<cstdio>
#include<iostream>
using namespace std;
//const int NMAX = ;
const int divmax = 25;
//int N;
long long P, Q, REZ;
long long dv[divmax], DIV;
long long nr[divmax];
void citire()
{
cin >> P >> Q;
}
void factor(long long x)
{
long long x2 = x;
for(long long i = 2 ; i * i <= x ; i++)
if(x2 % i == 0)
{
dv[++DIV] = i;
while(x2 % i == 0)
{
nr[DIV]++;
x2 /= i;
}
}
if(x2 > 1) dv[++DIV] = x2, nr[DIV]++;
for(int k = 1 ; k <= DIV ; k++)
nr[k] *= Q;
}
long long putere(long long x, long long elem)
{
long long total = 0, P = elem;
for(; elem <= x && elem > 0; elem =(long long)elem * P)
total += x / elem;
return total;
}
long long caut_bin(int k)
{
long long REZ = 0, P = (long long)1<<30 * 1<<30;
for(; P ; P >>= 1)
if(putere(REZ + P, dv[k]) < nr[k])
REZ += P;
return REZ + 1;
}
void scrie()
{
cout << REZ;
}
int main()
{
freopen("gfact.in", "r", stdin);
freopen("gfact.out", "w", stdout);
citire();
factor(P);
for(int k = 1 ; k <= DIV ; k++)
REZ = max(REZ, caut_bin(k));
scrie();
return 0;
}