Pagini recente » Cod sursa (job #1137734) | Cod sursa (job #1990074) | Cod sursa (job #2918154) | Cod sursa (job #2207591) | Cod sursa (job #2037156)
#include <stdio.h>
#include <math.h>
#define nmax 400000015
using namespace std;
int count5(long fact)
{
long i=5;
long zeros = 0;
while(fact/i!=0)
{
zeros+=fact/i;
i*=5;
}
return zeros;
}
long bs(long x)
{
long hi=nmax+1, lo=-1, mid;
while(hi-lo>1)
{
mid=(lo+hi)/2;
if(count5(mid)<x)
lo=mid;
else
hi=mid;
}
if(hi==nmax+1||count5(hi)!=x)
return -1;
return hi;
}
FILE *fin, *fout;
int main()
{
fin = fopen("fact.in","r");
fout = fopen("fact.out", "w");
long nr;
fscanf(fin, "%ld", &nr);
if(nr<0)
fprintf(fout, "-1");
else if(nr<5)
fprintf(fout, "1");
else
{long x = bs(nr);
if(x==0) x= 1;
fprintf(fout, "%ld", x);}
}