Cod sursa(job #2851404)

Utilizator alexandru.ciorneiAlexandru-Stefan Ciornei alexandru.ciornei Data 18 februarie 2022 16:19:10
Problema Factorial Scor 35
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.49 kb
#include <fstream>

using namespace std;

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

    int p = 0;
    fin >> p;

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

    if (nrzero == p)
        fout << n;
    else
        fout << -1;
    return 0;
}