Cod sursa(job #2988711)
Utilizator | Spar 13 spar13 | Data | 5 martie 2023 13:14:23 |
---|---|---|---|
Problema | Factorial | Scor | 100 |
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,r=-1;
while(s<=e) {
ll m=(s+e)/2,c=0;
for(ll i=5;i<=m;i*=5) {
c+=m/i;
}
if(c==p) {
r=m;
e=m-1;
}
else if(c<p) {
s=m+1;
}
else if(c>p) {
e=m-1;
}
}
fout<<r<<'\n';
}
int32_t main(){
ios::sync_with_stdio(0);
cin.tie(0);
int t=1;
//cin>>t;
while(t--){
solve();
}
}