Cod sursa(job #3349566)

Utilizator eric_dragosDragos Eric eric_dragos Data 31 martie 2026 19:17:36
Problema Factorial Scor 45
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.55 kb
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
int f(int x){
    int sol = 0;
    while(x/5 != 0){
        x /= 5;
        sol += x;
    }
    return sol;
    
}
int main(){
    int p, n;
    fin >> p;
    int l = 0, r =1e8+5;
    while(l <= r){
        int mid = l + (r-l)/2;
        if(f(mid) >= p){
            r = mid-1;
            n = mid;

        }
        else if (f(mid) < p){
            l = mid+1;
        } 
    }
    fout << n;

    return 0;
}