Cod sursa(job #2914497)

Utilizator alin.gabrielAlin Gabriel Arhip alin.gabriel Data 20 iulie 2022 07:24:58
Problema Factorial Scor 10
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.57 kb
#include <fstream>
using namespace std;
 
int find(int p) {
    int i = 0;
    int aux = 0;

    if (p == 0)
        return 1;

    while (p > 0) {
        i = i + 5;
        aux = i;
        if (aux % 25 == 0){
            do {
                p = p - 2;
                aux = aux / 25;
            } while (aux % 25 == 0);
        } else p--;
    }

    if (p < 0)
        return -1;

    return i;
}

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

    int n = find(p);

    fout<<n;
    return 0;
}