Cod sursa(job #2887972)

Utilizator hobbitczxdumnezEU hobbitczx Data 10 aprilie 2022 15:24:40
Problema Factorial Scor 90
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.67 kb
#include <bits/stdc++.h>
#define ll long long
#define INF 0x3F3F3F3F
using namespace std;

const string fisier = "fact";

ifstream fin (fisier + ".in");
ofstream fout (fisier + ".out");

int ans = 1e9 , n;

bool solve (int x){
    int cnt = 0;
    while (x > 0){
        cnt += x / 5;
        x = x / 5;
    }
    return (cnt >= n);
}

int main(){
    ios_base::sync_with_stdio(false);
    fin >> n;
    int l = 1 , r = 1e9;
    while (l <= r){
        int mid = l + (r - l) / 2;
        if (solve(mid)){
            ans = min(ans , mid);
            r = mid - 1;
        }
        else{
            l = mid + 1;
        }
    }
    fout << ans;
}