Pagini recente » Cod sursa (job #717162) | Cod sursa (job #2151067) | Cod sursa (job #16351) | Cod sursa (job #181995) | Cod sursa (job #2067527)
#include <fstream>
#include <map>
using namespace std;
map<int,int>puteri;
ifstream in("gfact.in");
ofstream out("gfact.out");
void descompunere(int n,int p){
int d=2;
while(d*d<=n){
if(n%d==0){
puteri[d]=0;
while(n%d==0)
n/=d,puteri[d]++;
}
d++;
}
if(n>1)
puteri[n]=1;
for(auto it=puteri.begin();it!=puteri.end();it++)
(*it).second*=p;
}
int legendre(int n,int d){
int rasp=0;
while(d<=n){
rasp+=(n/=d);
}
return rasp;
}
bool verif(int l){
for(auto it=puteri.begin();it!=puteri.end();it++){
if(legendre(l,(*it).first) >= (*it).second)
return 1;
}
printf("%d\n",l);
return 0;
}
int cbin(){
int pas=1<<30,d=0;
while(pas>0){
if(!verif(pas+d))
d+=pas;
pas/=2;
}
return d+1;
}
int main()
{
int p,q;
in>>p>>q;
descompunere(p,q);
out<<cbin();
return 0;
}