Cod sursa(job #2450640)

Utilizator OlteanuAlexandru67Olteanu Alexandru OlteanuAlexandru67 Data 23 august 2019 21:36:32
Problema Factorial Scor 100
Compilator cpp-32 Status done
Runda Arhiva de probleme Marime 1.06 kb

 #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll const mod=1000000007;
ll const md=998244353;
ll mypowr(ll a,ll b) {ll res=1;a%=mod; assert(b>=0);
for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll mypow(ll a,ll b) {ll res=1;assert(b>=0);
for(;b;b>>=1){if(b&1)res=res*a;a=a*a;}return res;}
ifstream in("fact.in");
ofstream out("fact.out");
#define mp make_pair
#define pb push_back
#define pf push_front
#define fi first
#define se second


int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    cout<<fixed<<setprecision(15);

    ll n;
    in>>n;
    if(n==0){
        out<<"1";exit(0);
    }
    ll cnt=-1;
    ll lo=1,hi=1e8;
    while(lo<=hi){
        ll mid=lo+(hi-lo)/2;
        ll u=5*mid;
        ll sum=0;
        while(u){
            sum+=u/5;
            u/=5;
        }
        if(sum==n){cnt=5*mid;lo=hi+1;}
        if(sum>n){
            hi=mid-1;
        }
        if(sum<n){
            lo=mid+1;
        }
    }
    out<<cnt<<'\n';





    return 0;
}