Pagini recente » Cod sursa (job #1053742) | Cod sursa (job #1353953) | Cod sursa (job #151012) | Cod sursa (job #2233680) | Cod sursa (job #3204450)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("gfact.in");
ofstream fout("gfact.out");
vector<pair<int, int>> fact;
void initFact(int x)
{
fact.reserve(10);
int exp=0;
while(x%2==0)
{
exp++;
x/=2;
}
if(exp>0)
fact.push_back(make_pair(2, exp));
for(int d=3; d*d<=x; d+=2)
{
exp=0;
while(x%d==0)
{
exp++;
x/=d;
}
if(exp>0)
fact.push_back(make_pair(d, exp));
}
if(x>1)
fact.push_back(make_pair(x, 1));
}
bool verifDiv(int n)
{
for(unsigned int i=0; i<fact.size(); i++)
{
int cnt=0;
while(fact[i].first<=n)
{
cnt+=(n/=fact[i].first);
if(cnt>=fact[i].second)
break;
}
if(cnt<fact[i].second)
return 0;
}
return 1;
}
long long cb()
{
long long st=1,dr=1078125000,mij,rez=-1;
while(st<=dr)
{
mij=(st+dr)/2;
if(verifDiv(mij))
{
rez=mij;
dr=mij-1;
}
else st=mij+1;
}
return rez;
}
int main()
{
int p,q;
fin>>p>>q;
initFact(p);
for(unsigned int i=0; i<fact.size(); i++)
{
fact[i].second*=q;
//cout<<fact[i].first<<' '<<fact[i].second<<'\n';
}
fout<<cb();
return 0;
}