Pagini recente » Cod sursa (job #825472) | Cod sursa (job #3296454)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("gfact.in");
ofstream fout("gfact.out");
long long p, q, fact[22], ex[22], nrf;
static inline void Desc(long long n) {
long long d = 2;
while(d * d <= n) {
if(n % d == 0) {
long long e = 0;
while(n % d == 0) {
e++;
n /= d;
}
nrf++;
fact[nrf] = d;
ex[nrf] = e;
}
d++;
}
if(n > 1) {
nrf++;
fact[nrf] = n;
ex[nrf] = 1;
}
}
static inline long long LaGrande(long long a, long long n) {
long long put = a;
long long ex = 0;
while(put <= n) {
ex += n / put;
put *= a;
}
return ex;
}
static inline bool Verif(long long n) {
for(long long i = 1; i <= nrf; i++) {
if(LaGrande(fact[i], n) < ex[i]) return false;
}
return true;
}
int main() {
fin >> p >> q;
Desc(p);
for(long long i = 1; i <= nrf; i++) ex[i] *= q;
long long st = 1, dr = 2000000000;
long long rasp = st;
while(st <= dr) {
long long mij = st + (dr - st) / 2;
if(Verif(mij)) {
rasp = mij;
dr = mij - 1;
}
else st = mij + 1;
}
fout << rasp;
return 0;
}