Pagini recente » Cod sursa (job #1116514) | Cod sursa (job #1077821) | Cod sursa (job #396790) | Cod sursa (job #2904332) | Cod sursa (job #1289715)
#include <stdio.h>
const char IN[] = "fact.in", OUT[] = "fact.out";
int P;
int count ( int x ) {
int ret = 0;
for ( int p = 5; p <= x; p *= 5 )
ret += x / p;
return ret;
}
bool test( int x ) {
return count(x) < P;
}
int search ( int L ) {
int i, step;
for ( step = 1; step < L; step <<= 1 );
for ( i = 0; step; step >>= 1 )
if ( i + step <= L && test(i + step) )
i += step;
if ( count(i + 1) == P )
return i + 1;
else
return -1;
}
int main() {
freopen(IN, "r", stdin);
freopen(OUT, "w", stdout);
scanf("%d", &P);
printf("%d\n", search(1000000000));
return 0;
}