Pagini recente » Cod sursa (job #1486654) | Cod sursa (job #2160490) | Cod sursa (job #1170323) | Cod sursa (job #1341156) | Cod sursa (job #601302)
Cod sursa(job #601302)
#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/5 * 5;
}
if(nrz(m) > p)
{
dr = m - 1;
}
else
{
st = m + 1;
}
}
return -1;
}
int main()
{
int nr, i, aux, st, dr;
FILE *fin = freopen("fact.in", "r", stdin);
FILE *fout = freopen("fact.out", "w", stdout);
scanf("%d", &p);
printf("%lld", binar(1,5*p));
}