Cod sursa(job #2287769)
| Utilizator | Data | 22 noiembrie 2018 14:59:49 | |
|---|---|---|---|
| Problema | GFact | Scor | 5 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva de probleme | Marime | 0.8 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("gfact.in");
ofstream out("gfact.out");
long long p,q,x,st,dr,mij,m5,s,ok;
int main()
{
in>>p>>q;
if(p==0)
out<<"1";
else
{
st=5;
dr=400000015;
while(st<=dr)
{
mij=(st+dr)/2;
x=mij;
m5=p;
s=0;
while(x/m5>0)
{
s=s+x/m5;
m5=m5*p;
}
if(s==q)
{
ok=1;
break;
}
else if(s<q)
st=mij+1;
else
dr=mij-1;
}
if(ok==1)
out<<mij/p*p;
else
out<<"-1";
}
return 0;
}
