Pagini recente » Cod sursa (job #1385136) | Cod sursa (job #1976961) | Cod sursa (job #1725372) | Cod sursa (job #2977866) | Cod sursa (job #107528)
Cod sursa(job #107528)
#include <cstdio>
int f ( int x ) {
int s = 0;
for (int a = x; a > 0; a /= 5) {
s += a/5;
}
return s;
}
int bsearch ( int val )
{
int step, i;
const int N = 0x3f3f3f3f;
for (step = 1; step < N; step <<= 1);
for (i = 0; step; step >>= 1) {
int x = f(i+step);
if (i + step < N && (x < val || (x == val && f(i+step-1) != val)))
i += step;
}
return i;
}
int main() {
freopen("fact.in","r",stdin);
freopen("fact.out","w",stdout);
int p;
scanf("%d",&p);
if (p == 0)
printf("1\n");
else {
int x = bsearch(p);
if (f(x) == p) printf("%d\n",x); else printf("-1\n");
}
return 0;
}