Pagini recente » Cod sursa (job #1312836) | Cod sursa (job #289667) | Cod sursa (job #444575) | Cod sursa (job #1688369) | Cod sursa (job #23955)
Cod sursa(job #23955)
#include <stdio.h>
int nzero ( int n ) {
int s = 0;
for (int i = 5; i<n; i*=5) {
s += n/i;
}
return s;
}
int bsearch(int val)
{
int i, step;
const int N = 1000000000;
for (step = 1; step < N; step <<= 1);
for (i = 0; step; step >>= 1) {
if (i + step < N && nzero(i + step) <= val)
i += step;
}
while (nzero(i-1) == val) --i;
return i;
}
int main() {
freopen("fact.in","r",stdin);
freopen("fact.out","w",stdout);
int n;
scanf("%d",&n);
int r = bsearch(n);
printf("%d\n",r);
return 0;
}