Pagini recente » Cod sursa (job #57367) | Cod sursa (job #2135624) | Cod sursa (job #481730) | Cod sursa (job #1048337) | Cod sursa (job #2663508)
#include <bits/stdc++.h>
#define MAX 131072
#define MOD 1000000007
using namespace std;
const int NMAX = 1005;
int P, Q, K;
int fact[NMAX], p[NMAX];
long long ans;
int main(){
freopen("gfact.in", "r", stdin);
freopen("gfact.out", "w", stdout);
scanf("%d%d", &P, &Q);
if(P % 2 == 0)
fact[++K] = 2;
while(P % 2 == 0){
p[K]++;
P /= 2;
}
for(int i = 3; i * i <= P; i += 2){
if(P % i != 0) continue;
fact[++K] = i;
while(P % i == 0){
++p[K];
P /= i;
}
}
if(P > 2){
fact[++K] = P;
p[K] = 1;
}
for(int i = 1; i <= K; ++i)
p[i] = p[i] * Q;
for(int i = 1; i <= K; ++i){
long long x = 0;
while(p[i] > 0){
x += fact[i];
long long y = x;
while(y % fact[i] == 0){
--p[i];
y /= fact[i];
}
}
ans = max(ans, x);
}
printf("%lld", ans);
return 0;
}