Cod sursa(job #2988706)

Utilizator spar13Spar 13 spar13 Data 5 martie 2023 13:07:24
Problema Factorial Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.63 kb
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

ifstream fin("fact.in");
ofstream fout("fact.out");

void solve(){
    int p;
    fin>>p;
    ll s=1,e=INT_MAX,c=0,r=-1;

    while(s<=e) {
        ll m=(s+e)/2;

        for(ll i=5;i<=m;i*=5) {
            c+=m/i;
        }

        if(c==p) {
            r=m;
            s=m-1;
        }
        else if(c<p) {
            s=m-1;
        }
        else if(c>p) {
            s=m+1;
        }
    }

    cout<<r<<'\n';
}

int32_t main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t=1;
    //cin>>t;
    while(t--){
        solve();
    }
}