Pagini recente » Cod sursa (job #2817955) | Cod sursa (job #2368854) | Cod sursa (job #1259365) | Cod sursa (job #2202377) | Cod sursa (job #2661274)
#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, e = n;
for ( pos=-1, step = (1 << 30); step; step >>= 1)
if (legendre(pos + step) <= e)
pos += step;
if (legendre(pos) != e)
return -1;
return pos;
}
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;
}