Cod sursa(job #472696)
| Utilizator | Data | 26 iulie 2010 12:58:30 | |
|---|---|---|---|
| Problema | Factorial | Scor | 45 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.5 kb |
#include <iostream>
#include <fstream>
using namespace std;
fstream fin("fact.in",ios::in),fout("fact.out",ios::out);
int n,lo,hi,p,x;
int zero(int n) {
int rez=0;
for(int imp=5; imp<=n;imp*=5) {
rez+=n/imp;
}
return rez;
}
int main()
{
fin>>n;
lo=5; hi=100000000;
x=-1;
while (lo<hi) {
p=zero((lo+hi)/2);
if (n>p) lo=(lo+hi)/2;
else if (n==p) {x=(lo+hi)/2; break;}
else hi=(lo+hi)/2;
}
while (x%5!=0) x--;
fout<<x<<"\n";
fout.close();
return 0;
}
