Pagini recente » Cod sursa (job #2457499) | Cod sursa (job #1596400) | Cod sursa (job #1057465) | Cod sursa (job #2445191) | Cod sursa (job #1242915)
#include <cstdio>
using namespace std;
int m (int a) {
int b = 5, s = 0;
while (a / b) {
s = s + a / b;
b = b * 5;
}
return s;
}
int main () {
int n, p, step, c, i, T;
freopen ("fact.in", "r", stdin);
freopen ("fact.out", "w", stdout);
scanf ("%d", &p);
if (p == 0) {
printf ("1\n");
return 0;
}
step = 2000000000;
for (n = 0; step; step >>= 1) {
if (m (n + step) < p)
n = n + step;
}
n ++;
while (n % 5) n ++;
if (m (n) == p)
printf ("%d\n", n);
else printf ("-1\n");
return 0;
}