Cod sursa(job #2975712)

Utilizator DooMeDCristian Alexutan DooMeD Data 7 februarie 2023 10:46:52
Problema Factorial Scor 60
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.51 kb
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int nmax = 1e8;
const int lgmax = 28;

int cnt(int x) {
    int nr = 0;
    for(int i=5; i<=x; i*=5)
        nr += x/i;
    return nr;
}

int32_t main() {
    ifstream f("fact.in");
    ofstream g("fact.out");

    int n; f >> n;
    int ans = 0;
    for(int p=lgmax; p>=0; p--)
        if(ans + (1<<p) <= nmax and cnt(ans+(1<<p)) < n)
            ans += (1<<p);
    g << (cnt(ans+1) == n ? ans+1 : -1);
    return 0;
}