Pagini recente » Cod sursa (job #2981128) | Cod sursa (job #708850) | Cod sursa (job #2943356) | Cod sursa (job #2028893) | Cod sursa (job #2661276)
#include <stdio.h>
using namespace std;
int legendre(int n) {
int cate = 0;
while ( n > 0 ) {
cate += n / 5;
n /= 5;
}
return cate;
}
int cb(int n) {
int pos, step;
for ( pos=-1, step = (1 << 26); step; step >>= 1)
if (legendre(pos + step) < n)
pos += step;
if (legendre(pos + 1) != n)
return -1;
return pos + 1;
}
int main() {
FILE *fin, *fout;
int n;
fin = fopen("fact.in", "r");
fscanf( fin, "%d", &n );
fclose( fin );
fout = fopen("fact.out", "w");
fprintf(fout, "%d\n", (n == 0? 1: cb(n)) );
fclose( fout );
return 0;
}