Pagini recente » Cod sursa (job #905724) | Cod sursa (job #3293022) | Cod sursa (job #838919) | Cod sursa (job #386638) | Cod sursa (job #1581)
Cod sursa(job #1581)
#include <stdio.h>
const char *fin = "fact.in";
const char *fout = "fact.out";
int hasZeros(unsigned int num, unsigned int zeros) {
unsigned int z = 0, pow = 5;
while (pow <= num) {
z += num / pow;
pow *= 5;
}
return (z >= zeros) ? 1 : 0;
}
int bins(unsigned int from, unsigned int to, unsigned int zeros) {
if (from >= to) {
return from;
}
int m = (from + to) / 2;
if (hasZeros(m, zeros)) {
return bins(from, m, zeros);
}
return bins(m + 1, to, zeros);
}
int main() {
unsigned int p = 0;
FILE *f = fopen(fin, "rt");
fscanf(f, "%d", &p);
fclose(f);
f = fopen(fout, "wt");
fprintf(f, "%d", bins(1, 5 * p + 1, p));
fclose(f);
}