Cod sursa(job #2974160)

Utilizator gabriel10tm@gmail.comGabriel Marian [email protected] Data 3 februarie 2023 14:14:01
Problema Factorial Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.64 kb
#include <iostream>

using namespace std;
/*
nr de m2 e mai mare decat m5
=> rez este m5
cati multipli de 5 sunt inaintea lui 45
5 10 15 20 5*5 30 35 40 45 - 10
*/
int pws[13];
int main()
{
    int n;
    cin >> n;
    int pw = 1;
    for(int i=0;i<13;i++){
        pws[i] = pw;
        pw *= 5;
    }
    if(n == 0){
        cout << 1 << '\n';
        return 0;
    }
    int res = 0;
    int cnt = 0;
    while(cnt<n){
        res += 5;
        for(int j=12;j>0;j--){
            if(res%pws[j]==0){
                cnt += j;
                break;
            }
        }
    }
    cout << (cnt==n ? res : -1);
}