Pagini recente » Cod sursa (job #2101227) | Cod sursa (job #212758) | Cod sursa (job #2588319) | Cod sursa (job #2344535) | Cod sursa (job #1803512)
#include <stdio.h>
#define L 27
inline int zero(int n) {
int total = 0;
while(n) {
total += n / 5;
n /= 5;
}
return total;
}
inline int caut2(int x) {
int r = 0;
int pos = 1 << L;
while(pos) {
if(r + pos <= 1 << L && zero(r + pos) < x)
r += pos;
pos /= 2;
}
if(x == zero(r + 1))
return r + 1;
return -1;
}
FILE *fin, *fout;
int main() {
fin = fopen("fact.in", "r");
fout = fopen("fact.out", "w");
int p;
fscanf(fin, "%d", &p);
fprintf(fout, "%d", caut2(p));
fclose(fin);
fclose(fout);
return 0;
}