Cod sursa(job #2783497)

Utilizator PopMatei77Matei Pop PopMatei77 Data 14 octombrie 2021 16:12:42
Problema Factorial Scor 5
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.49 kb
#include <iostream>
#include <fstream>
#include <cmath>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
int nz(long long n) {
    int p = 5;
    int s = 0;
    while (p <= n) {
        s += n / p;
        p *= 5;
    }
    return s;
}

int main() {
    int c = 5;
    int p;
    fin >> p;
    while (nz(c) <= p) {
        c += 5;
    }
    if (p == 0)
        cout << 1;
    if (nz(c) != p)
        fout << -1;
    else
        fout << c - 5;

}