Cod sursa(job #1501218)
Utilizator | Data | 13 octombrie 2015 06:56:27 | |
---|---|---|---|
Problema | Factorial | Scor | 85 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.46 kb |
#include <fstream>
using namespace std;
ifstream in("fact.in");
ofstream o("fact.out");
int p;
inline int calc(int n){
int ct=0;
while(n){
ct+=n/5;
n/=5;
}
return ct;
}
int main()
{
in >> p;
int st = 0,dr = 100000000000,m;
while(st<=dr){
m=(st+dr)/2;
if(calc(m)<p)
st = m+1;
else
dr = m-1;
}
o << st?1:(calc(st)==p)?st:-1;
return 0;
}