Pagini recente » Cod sursa (job #1973354) | Cod sursa (job #1975652) | Cod sursa (job #1195773) | Cod sursa (job #2845328) | Cod sursa (job #601307)
Cod sursa(job #601307)
#include <stdio.h>
#include <math.h>
int p;
int nrz(int n)
{
int fact, z;
fact = 5;
z = 0;
while(fact <= n)
{
z += floor(n / fact);
fact *= 5;
}
return z;
}
long long binar(long long st, long long dr)
{
long long m;
while(st<=dr)
{
m = (st+dr)/2;
if(nrz(m) == p)
{
return m/(long long int)(5) * 5;
}
if(nrz(m) > p)
{
dr = m - 1;
}
else
{
st = m + 1;
}
}
return -1;
}
int main()
{
FILE *fin = freopen("fact.in", "r", stdin);
FILE *fout = freopen("fact.out", "w", stdout);
scanf("%d", &p);
if(p==0) {
printf("1");
}
else {
printf("%lld", binar(1,5*p));
}
}