Cod sursa(job #2851421)

Utilizator alexandru.ciorneiAlexandru-Stefan Ciornei alexandru.ciornei Data 18 februarie 2022 17:03:06
Problema Factorial Scor 50
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.56 kb
#include <fstream>

using namespace std;

int main() {
    ifstream fin("fact.in");
    ofstream fout("fact.out");

    int p = 0;
    fin >> p;

    if (p == 0) {
        fout << 1;
    } else {
        unsigned long long int n = 5;
        int nrzero = 1;
        while (nrzero < p) {
            n += 5;
            unsigned long long int aux = n;
            while (aux % 5 == 0) {
                nrzero++;
                aux /= 5;
            }
        }
        if (nrzero == p)
            fout << n;
        else
            fout << -1;
    }

    return 0;
}