Cod sursa(job #2151755)
Utilizator | Agache Mihai MikeStrike | Data | 4 martie 2018 21:15:16 |
---|---|---|---|
Problema | Factorial | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.57 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("fact.in");
ofstream out("fact.out");
int p,n,st,dr;
int main()
{
in>>p;
st=1;
dr=(1<<30);
while(st<=dr)
{
int mij=(st+dr)/2;
int pow=5,x=0;
while(pow<=mij)
{
x=x+mij/pow;
pow=pow*5;
}
if(x>=p)
dr=mij-1;
else st=mij+1;
}
int pow=5,x=0;
while(pow<=st)
{
x=x+st/pow;
pow=pow*5;
}
if(x!=p) out<<-1;
else out<<st;
return 0;
}