Pagini recente » Cod sursa (job #1738065) | Cod sursa (job #1073563) | Cod sursa (job #866775) | Cod sursa (job #1059447) | Cod sursa (job #2954813)
#include <iostream>
using namespace std;
FILE *in = fopen("fact.in", "r"), *out = fopen("fact.out", "w");
int P;
int nr_of_zeros (int n){
int res = 0, div = 5;
while (div <= n){
res += n / div;
div *= 5;
}
return res;
}
int BS (int L, int R, int P){
int M, val;
while (L <= R){
M = (L + R) / 2;
val = nr_of_zeros(M);
if (P < val)
R = M - 1;
else if (P > val)
L = M + 1;
else {
while (nr_of_zeros(M - 1) == val)
--M;
return M;
}
}
return -1;
}
int main()
{
fscanf(in, "%d", &P);
int N;
if (P == 0)
N = 1;
else
N = BS(1, 100000000, P);
fprintf(out, "%d", N);
return 0;
}