Cod sursa(job #1660764)

Utilizator Alexghita96Ghita Alexandru Alexghita96 Data 23 martie 2016 13:33:21
Problema Factorial Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.47 kb
#include <iostream>
#include <fstream>

using namespace std;

int P;
int N = 0;
int trailingZeros = 0;

void solve() {
    while (trailingZeros < P) {
        N += 5;
        int aux = N;

        while (aux % 5 == 0) {
            aux /= 5;
            trailingZeros++;
        }
    }

    cout << N;
}

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

    cin >> P;
    if (P == 0) {
        cout << 1;
        return 0;
    }

    solve();
}