Pagini recente » Cod sursa (job #185472) | Cod sursa (job #1758410) | Cod sursa (job #3190297) | Cod sursa (job #2529997) | Cod sursa (job #2085047)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
ifstream in("gfact.in");
ofstream out("gfact.out");
long long int p,q;
void cit(){
in>>p>>q;
}
void afis(vector<pair<long long int,long long int> >perechi){
for(pair<long long int,long long int> it : perechi)
cerr<<it.first<<"^"<<it.second<<"\n";
}
void diviz(long long int p,vector<pair<long long int,long long int> >&perechi){
long long int d = 2,cnt;
while(p > 1){
cnt = 0;
if(p % d == 0){
while(p % d == 0){
p /= d;
cnt++;
}
perechi.push_back(make_pair(d,cnt * q));
}
d++;
}
if(p != 1)
perechi.push_back(make_pair(p,1));
}
bool validare(long long int x,vector<pair<long long int,long long int> > perechi_p){
bool mlc = true;
for(pair<long long int,long long int>it : perechi_p){
int a = it.first;
int p = it.second;
int cnt = 0;
while(x >= a){
x /= a;
cnt += a;
}
mlc &= p >= cnt;
}
return mlc;
}
void cautbin(){
long long int pas = 1LL<<50,r = 0;
vector<pair<long long int,long long int> >perechi_p;
diviz(p,perechi_p);
while(pas){
if(validare(r+pas,perechi_p) == true)
r += pas;
pas /= 2;
}
r ++;
out<<r;
}
int main()
{
cit();
cautbin();
return 0;
}