Pagini recente » Cod sursa (job #1441679) | Cod sursa (job #764530) | Statistici PauletStefan (Paulet.Stefan) | Cod sursa (job #220943) | Cod sursa (job #971282)
Cod sursa(job #971282)
#include<stdio.h>
#define NMax 100000000
long i, j, n;
long f(int x)
{
long a = 5, rez = 0;
while(x / a) {
rez += x / a;
a *= 5;
}
return rez;
}
int main()
{
freopen("fact.in", "rt", stdin);
freopen("fact.out", "wt", stdout);
scanf("%ld", &n);
if(n == 0) printf("0\n");
else
{
int inc = 0, sf = NMax, mid, val;
bool ok = false;
while (inc <= sf && !ok) {
mid = (inc + sf) / 2;
val = f(mid);
if(val < n) inc = mid + 1;
else if(val > n) sf = mid - 1;
else ok = true;
}
if(ok)
{
while (mid % 5) mid--;
printf("%d", mid);
}
else printf("-1\n");
}
return 0;
}