Cod sursa(job #479347)
Utilizator | Nea Caisa proxenetu | Data | 23 august 2010 18:56:18 |
---|---|---|---|
Problema | Factorial | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.38 kb |
#include <stdio.h>
int fact (int N) {
int sum = 0, step;
for (step = 5; step <= N; step *= 5)
sum += N / step;
return sum;
}
int main () {
int N, step, i;
freopen("fact.in", "r", stdin);
freopen("fact.out", "w", stdout);
scanf("%d", &N);
for (step = 1 << 29, i = 0; step; step >>= 1)
if (fact(i + step) < N)
i += step;
printf("%d\n", fact(i + 1) == N ? i + 1 : -1);
}