Cod sursa(job #2807567)

Utilizator hoprixVlad Opris hoprix Data 23 noiembrie 2021 22:19:41
Problema Factorial Scor 90
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.61 kb
#include <bits/stdc++.h>
using namespace std;

int zeros(int n) {
    int z = 0;
    while (n > 4) {
        z += n/5;
        n /= 5;
    }
    return z;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    ifstream fin("fact.in");
    ofstream fout("fact.out");
        
    int P; fin >> P;

    int st = 1, dr = 1<<30, N = 1;
    while (st <= dr) {
        int mj = (st+dr)/2;
        int Z = zeros(mj);
        if (Z < P) 
            st = mj+1;
        else if (Z >= P) {
            dr = mj-1;
            N = mj;
        }
    }
    fout << N;

    return 0;
}