Cod sursa(job #2281358)
Utilizator | Data | 12 noiembrie 2018 08:44:05 | |
---|---|---|---|
Problema | Factorial | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva de probleme | Marime | 0.53 kb |
#include<fstream>
#include<algorithm>
using namespace std;
ifstream cin("fact.in");
ofstream cout("fact.out");
typedef unsigned long long ull;
ull ans,step,i,p;
ull rez(ull x){
ull r=0;
while(x){
r+=x/5;
x/=5;
}
return r;
}
int main(){
cin>>p;
if(p==0){
cout<<1;
return 0;
}
i=0;
step=(1LL<<63);
while(step){
if(rez(i+step)<=p)
i+=step;
step>>=1;
}
if(rez(i+step)!=p) cout<<-1;
else cout<<(i-4);
}