Pagini recente » Cod sursa (job #3182137) | Cod sursa (job #1208401) | Cod sursa (job #339614) | Cod sursa (job #257938) | Cod sursa (job #2106083)
#include <bits/stdc++.h>
#define ll long long
#define N 45000
using namespace std;
ifstream in("gfact.in");
ofstream out("gfact.out");
ll p, q, vf, nr, divi[50], pw[50], st, dr, mid;
vector <ll> primes;
bool viz[N];
bool ok(ll val, ll pos){
ll cnt = 0, aux = divi[pos];
while(aux <= val){
cnt += val / aux;
if(cnt >= pw[pos])
return 1;
if(divi[pos] > val / aux)
break;
aux *= divi[pos];
}
return 0;
}
bool check(ll val){
for(int i = 1; i <= vf; i++)
if(!ok(val, i))
return 0;
return 1;
}
int main(){
in >> p >> q;
for(int i = 2; i <= N; i++)
if(!viz[i]){
primes.push_back(i);
for(int j = i + i; j <= N; j += i)
viz[j] = 1;
}
for(auto i : primes){
if(i * i > p)
break;
if(p % i)
continue;
nr = 0;
while(p % i == 0){
nr++;
p /= i;
}
divi[++vf] = i;
pw[vf] = nr;
}
if(p > 1){
divi[++vf] = p;
pw[vf] = 1;
}
for(int i = 1; i <= vf; i++)
pw[i] *= q;
st = 1, dr = (ll)1e18;
while(st <= dr){
mid = st + (dr - st) / 2;
if(check(mid))
dr = mid - 1;
else
st = mid + 1;
}
out << st;
return 0;
}