Cod sursa(job #2974161)

Utilizator gabriel10tm@gmail.comGabriel Marian [email protected] Data 3 februarie 2023 14:15:25
Problema Factorial Scor 30
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.74 kb
#include <bits/stdc++.h>

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];
#if 1
#define cin fin
#define cout fout
ifstream fin("fact.in");
ofstream fout("fact.out");
#endif
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);
}