Cod sursa(job #2515008)
| Utilizator | Data | 27 decembrie 2019 16:35:50 | |
|---|---|---|---|
| Problema | Factorial | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva de probleme | Marime | 0.64 kb |
//#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream cin("fact.in");
ofstream cout("fact.out");
long long p;
cin>>p;
long long st=1,dr=1000000000000000000,sol;
while(st<=dr){
long long mid=(st+dr)/2,sum=0;
long long x=mid;
while(x){
sum+=x/5;
x/=5;
}
if(sum>=p){
sol=mid;
dr=mid-1;
}
else{
st=mid+1;
}
}
long long sum=0,cp=sol;
while(cp){
sum+=cp/5;
cp/=5;
}
if(sum==p){
cout<<sol;
}
else
cout<<-1;
return 0;
}
