Cod sursa(job #3349574)

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

    return 0;
}