Pagini recente » Cod sursa (job #261355) | Cod sursa (job #2624990) | Cod sursa (job #2533831) | Cod sursa (job #1309754) | Cod sursa (job #1367915)
#include <fstream>
#include <iostream>
#define nmax 400000015
using namespace std;
int main ()
{
unsigned long long n=0,p,x,f,ld=nmax,ls=5,g=0;
ifstream h ("fact.in");
ofstream k ("fact.out");
h>>p;
if (p==0)
k<<1;
else
{
while (ls<=ld && g==0)
{
n=(ls+ld)/2;
x=0;
f=5;
while(f<=n)
{
x=x+n/f;
f=f*5;
}
if (x==p)
{
k<<n/5*5;
g=1;
}
else if (x<p) ls=n+1;
else ld=n-1;
}
if (g==0)
k<<-1;
}
return 0;
}