Pagini recente » Cod sursa (job #1173166) | Cod sursa (job #3244545) | Cod sursa (job #1270432) | Cod sursa (job #1179520) | Cod sursa (job #2289696)
#include <stdio.h>
using namespace std;
int nr_zero(int x) {
int nr = 0, div = 5;
while (div <= x) {
nr += x / div;
div *= 5;
}
return nr;
}
int caut(int p) {
if (!p)
return 1;
int pos, i;
for (pos = 1; pos < 5 * p; pos <<= 1);
for (i = 5 * p, pos >>= 1; pos; pos >>= 1)
if (i - pos >= 0 && nr_zero(i - pos) >= p)
i -= pos;
if (nr_zero(i) == p)
return i;
return -1;
}
int main()
{
freopen("fact.in", "r", stdin);
freopen("fact.out", "w", stdout);
int p;
scanf("%i", &p);
printf("%d", caut(p));
return 0;
}