Cod sursa(job #2287784)
Utilizator | Data | 22 noiembrie 2018 15:17:27 | |
---|---|---|---|
Problema | GFact | Scor | 0 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva de probleme | Marime | 0.64 kb |
#include <fstream>
using namespace std;
ifstream in("gfact.in");
ofstream out("gfact.out");
int p,q,st,dr,last=0;
int main()
{
in>>p>>q;
st=1;
dr=1000000000;
int mij,x;
while(st<dr)
{
mij=(st+dr)/2;
x=mij;
int s=0,mp=p;
while(x/mp>0)
{
s=s+x/mp;
mp=mp*p;
}
if(s==q)
{
last=mij;
break;
}
else if(s>q)
{
last=mij;
dr=mij-1;
}
else
{
st=mij+1;
}
}
out<<last-q/2;
return 0;
}