Pagini recente » Cod sursa (job #2726166) | Cod sursa (job #92672) | Cod sursa (job #1817620) | Cod sursa (job #2233791) | Cod sursa (job #1734249)
#include <fstream>
#include <math.h>
#include <algorithm>
#include <unordered_map>
using namespace std;
#define ll long long
#define llu long long unsigned
#define pb push_back
#define mp make_pair
string problemName = "gfact";
string inFile = problemName+".in";
string outFile = problemName+".out";
ifstream fin(inFile.c_str());
ofstream fout(outFile.c_str());
unordered_map <int, int> need;
void desc(int p, int q){
int i,aux,c;
c = 0;
while(p%2 == 0){
c++;
p /= 2;
}
if(c){
need[2] = c*q;
}
for(i = 3;i*i <= p;i += 2){
if(p%i == 0){
c = 0;
while(p%i == 0){
c++;
p /= i;
}
need[i] = c*q;
}
}
if(p > 1){
need[p] = q;
}
}
int main(){
int p,q,i,aux,c,target,x;
fin>>p>>q;
desc(p, q);
int mn = 2e9;
for(auto it : need){
x = it.first;
target = it.second;
c = 0;
for(i = x;;i += x){
aux = i;
while(aux%x == 0){
c++;
aux /= x;
}
if(c >= target){
mn = min(mn, i);
break;
}
}
}
fout<<mn;
return 0;
}