Cod sursa(job #1711434)
| Utilizator | Data | 31 mai 2016 11:09:58 | |
|---|---|---|---|
| Problema | GFact | Scor | 20 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.59 kb |
#include <fstream>
using namespace std;
ifstream in("gfact.in");
ofstream out("gfact.out");
int pas=1<<30,p,q,maxdiv;
int nr(int);
int main()
{
int a,i=0,d=2,cop;
in >> p >> q;
cop=p;
for(d=2;d*d<=cop;++d)
while(cop%d==0)
{
cop/=d;
maxdiv=d;
}
if(cop>1) maxdiv=cop;
while(pas)
{
if(nr(i+pas)<=q)
i+=pas;
pas/=2;
}
while(nr(i)==q)
--i;
out << ++i;
return 0;
}
int nr(int n)
{
int div=0;
while(n>=maxdiv)
{
div+=n/maxdiv;
n/=maxdiv;
}
return div;
}
