Pagini recente » Cod sursa (job #349258) | Cod sursa (job #1381509) | Cod sursa (job #2598710) | Cod sursa (job #2184642) | Cod sursa (job #2085130)
#include <iostream>
#include <fstream>
#include <vector>
typedef unsigned long long int u;
using namespace std;
ifstream in("gfact.in");
ofstream out("gfact.out");
int p,q;
vector<pair<int,u> >perechi;
bool validare(u x){
bool ok = false;
for(pair<int,int>it : perechi){
u a = it.first;
u p = it.second;
u cnt = 0;
while(x >= a){
cnt += x / a;
a *= it.first;
}
if(p <= cnt)
ok = true;
}
return ok;
}
int main()
{
in>>p>>q;
//divizori
int d = 2;
u cnt;
while(d*d <= p){
cnt = 0;
if(p % d == 0){
while(p % d == 0){
p /= d;
cnt++;
}
perechi.emplace_back(p,cnt*q);
}
d++;
}
if(p != 1)
perechi.emplace_back(p,q);
//cautare binara
u pas = 1LL<<45,r = 0;
while(pas){
if(validare(r+pas) == false)
r += pas;
pas >>=1;
}
out<<r+1;
return 0;
}