Cod sursa(job #589255)
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <time.h>
FILE *in = fopen ("fact.in","r"), *out = fopen("fact.out","w");
int p;
long long nrz(long long n)
{
long long s = 0;
while (n)
{
s += n / 5;
n = n / 5;
}
return s;
}
void find()
{
long long st = 1, dr = 1000000000000000000LL;
while (st < dr)
{
long long m = st + (dr - st) / 2;
if (nrz(m) < p)
st = m + 1;
else
dr = m;
}
if (nrz(st) != p)
fprintf(out, "-1");
else
fprintf(out, "%lld", st);
}
int main()
{
fscanf(in, "%d", &p);
find();
return 0;
}