Cod sursa(job #3170063)

Utilizator andrei_btwAndrei Nastasa andrei_btw Data 16 noiembrie 2023 19:05:34
Problema Factorial Scor 15
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.52 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
int nz(int n) {
    int c2 = 0, c5 = 0;

    for (int i = 2; i <= n; i *= 2)
    {
        c2 += n / i;
    }

    for (int i = 5; i <= n; i *= 5)
    {
        c5 += n / i;
    }

    return c5;
}

int main() {
    int p;
    fin >> p;
    int i = 1;
    bool ok = false;
    while (ok == false) {
        if (nz(i) == p) ok = true;
        i++;
    }
    fout << i - 1;
    return 0;
}