Cod sursa(job #2731992)

Utilizator Sho10Andrei Alexandru Sho10 Data 28 martie 2021 16:38:01
Problema Factorial Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1 kb
#include <bits/stdc++.h> //Andrei Alexandru a.k.a Sho10
#define ll long long
#define double long double
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define aint(a) (a).begin(), (a).end()
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define endl '\n'
#define mod 1000000007
#define PI 3.14159265359
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005ll
#define CODE_START  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll cnt;
ll check(ll x){
ll res=0;
ll val=5;
while(val<=x){
    res+=x/val;
    val*=5;
}
return res;
}
int32_t main(){
CODE_START;
ifstream cin("fact.in");
ofstream cout("fact.out");
cin>>cnt;
ll l=1,r=9999999999999,res=0;
while(l<=r){
    ll mid=(l+r)/2;
    if(check(mid)<cnt){
        l=mid+1;
    }else {
    res=mid;
    r=mid-1;
    }
}
if(check(res)!=cnt){
    cout<<"-1"<<endl;
}else
cout<<res<<endl;
}