Cod sursa(job #656550)

Utilizator bia.liliPoenar Liana bia.lili Data 4 ianuarie 2012 19:55:21
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.38 kb
#include <fstream>
using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");
int n,p,u,m; 
int putere(int v) {
int x=0,c=5;
while (v>=c) {
x+=v/c;
c*=5;

}return x;
} 
int main () {
f >> n;
p=1;u=5*n;
while (p<=u) {
m=(p+u)/2;
if (putere(m)<n) p=m+1;
else u=m-1;
}
if (putere(p)==n) g << p << '\n';
else g << -1 << '\n';
f.close();g.close();
return 0;
}