Pagini recente » Cod sursa (job #1596914) | Cod sursa (job #1686058) | Cod sursa (job #1521176) | Cod sursa (job #1265730) | Cod sursa (job #2037150)
#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;
}
int bs(long x)
{
int 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
fprintf(fout, "%ld", bs(nr));
}