Cod sursa(job #2287794)
| Utilizator | Data | 22 noiembrie 2018 15:22:54 | |
|---|---|---|---|
| Problema | GFact | Scor | 0 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva de probleme | Marime | 0.68 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,mp,s;
while(st<dr)
{
mij=(st+dr)/2;
x=mij;
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)
{
if(last>=mij)
last=mij;
dr=mij-1;
}
else
{
st=mij+1;
}
}
out<<last;
return 0;
}
