Cod sursa(job #1645899)
| Utilizator | Data | 10 martie 2016 14:17:05 | |
|---|---|---|---|
| Problema | Factorial | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.78 kb |
#include <fstream>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
int i , j, c, p;
long long st, dr, x, mid, y;
int main()
{
fin>>p;
if(p==1){
fout<<5;
return 0;
}
if(p==0){
fout<<1;
return 0;
}
st=1;
dr=10000000000000;
while(st<=dr){
mid=(st+dr)/2;
x=5;y=0;
while(x<=5*mid){
y+=mid/x;x=5*x;
}
//fout<<y<< " ";
if(p==y){
while(mid % 5 !=0)
mid--;
break;
}
else{
if(p>y)
st=mid+1;
else
dr=mid-1;
}
}
if(st<=dr)
fout<<mid;
else
fout<<-1;
return 0;
}
