Cod sursa(job #2961271)

Utilizator gripzStroescu Matei Alexandru gripz Data 6 ianuarie 2023 02:28:01
Problema Factorial Scor 25
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.54 kb
#include <iostream>

using namespace std;

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

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

    int c5 = 0, c2 = 0;

    int i = 1;
    while(c5 < P || c2 < P) {
        int i2 = i;
        while(i2 % 5 == 0) {
            i2 /= 5;
            c5++;
        }

        while(i2 % 2 == 0) {
            i2 /= 2;
            c2++;
        }

        i++;
    }

    cout << i - 1;

    return 0;
}