Cod sursa(job #2887979)

Utilizator hobbitczxdumnezEU hobbitczx Data 10 aprilie 2022 15:32:08
Problema Factorial Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.71 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");

ll n;

ll solve (ll n){
    ll ans = 0;
    while (n){
        ans += n / 5;
        n = n / 5;
    }
    return ans;
}

ll cb (ll n){
    ll st = 1 , dr = 1e18 , ans;
    while (st <= dr){
        ll mij = (st + dr) / 2;
        if (solve(mij) >= n){
            dr = mij - 1;
            ans = mij;
        }
        else{
            st = mij + 1;
        }
    }
    return ((solve(ans) == n) ? ans : -1);
}

int main(){
    ios_base::sync_with_stdio(false);
    fin >> n;
    fout << cb(n);
}