Pagini recente » Cod sursa (job #1213767) | Cod sursa (job #2624549)
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("fact.in");
ofstream out("fact.out");
int Zero(long X)
{
int number=0;
int fives=5;
while(fives<=X)
{
number+=X/fives;
fives*=5;
}
return number;
}
long Fact(long P)
{
if(P==0)
return 1;
else
{
int st=0;
int dr=P*5;
int result;
while(st<=dr)
{
int mij=(st+dr)/2;
if(Zero(mij)<=P)
{
result=mij;
st=mij+5;
}
else
dr=mij-5;
}
if(Zero(result)== P)
return result - result%5;
else
return -1;
}
}
int main()
{
long P;
cin>>P;
cout<<Fact(P);
return 0;
}