Cod sursa(job #2633238)

Utilizator OvidRata Ovidiu Ovid Data 6 iulie 2020 19:43:16
Problema Factorial Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.86 kb
#include<bits/stdc++.h>
using namespace std;
#define INIT  ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define mp make_pair
#define pb push_back
#define ft first
#define sc second
#define ll long long
#define pii pair<int, int>
#define count_bits __builtin_popcount
#define int ll
 ifstream fin("fact.in"); ofstream fout("fact.out");
#define cin fin
#define cout fout

int p;


int32_t main(){
INIT
cin>>p;


int l=1, r=10e10;
int m;
while(l<r){
    m=(l+r)/2;
    int f=0;
    int m0=m;
    while(m0>0){
        m0/=5; f+=m0;
    }
    if(f>=p){
        r=m;
    }
    else{
        l=m+1;
    }
    m=(l+r)/2;
}

int f=0;
int m0=m;
while(m0>0){
    m0/=5; f+=m0;
}

if(f==p){
    cout<<m;
}
else{
    cout<<"-1";
}


return 0;
}