Pagini recente » Cod sursa (job #3164405) | Cod sursa (job #215502) | Cod sursa (job #3161635) | Cod sursa (job #3177380) | Cod sursa (job #2987706)
#include <fstream>
#include <climits>
using namespace std;
ifstream in ("fact.in");
ofstream out ("fact.out");
int verif (long long n)
{
long long fact=5;
int cnt=0;
while(fact<=n)
{
cnt+=n/fact;
fact*=5;
}
return cnt;
}
int main()
{
long long p,st=1,dr=INT_MAX,m,q;
in>>p;
if(p==1)
{
out<<1;
return 0;
}
while(st<=dr)
{
m=((st+dr)/2)*5;
q=verif(m);
if(q<p)
st=(m+5)/5;
else if(q>p)
dr=(m-5)/5;
else
{
out<<m;
return 0;
}
}
out<<-1;
return 0;
}