Cod sursa(job #630205)

Utilizator silviuboganSilviu Bogan silviubogan Data 4 noiembrie 2011 21:42:02
Problema Factorial Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.53 kb
#include <cstdio>
using namespace std;

inline int zerosAtEndOfFact (long int x) {
    int s = 0, pow5 = 5;
    while (x > pow5) {
        s += x / pow5;
        pow5 *= 5;
    }
    return s;
}

int main () {
    int P, i = 1;

    freopen("fact.in", "r", stdin);
    freopen("fact.out", "w", stdout);

    scanf("%d", &P);

    while (i <= 100000000) {
        if (zerosAtEndOfFact(i) == P) {
            printf("%d", i);
            return 0;
        }
        i++;
    }

    printf("%d", -1);
    return 0;
}