Cod sursa(job #95608)
| Utilizator | Data | 29 octombrie 2007 17:52:28 | |
|---|---|---|---|
| Problema | Factorial | Scor | 55 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.58 kb |
#include <stdio.h>
long p,a = 1,b = 100000000,gasit;
long zerouri (int x)
{
long put = 0;
while (x > 0)
{
put += x / 5;
x /= 5;
}
return put;
}
int main ()
{
long aux;
freopen("fact.in","r",stdin);
freopen("fact.out","w",stdout);
scanf("%ld",&p);
while (a != b && !gasit)
{
aux = zerouri((a+b)/2);
if (aux == p)
gasit = 1;
else
if (aux < p)
a = (a+b)/2 +1;
else
b = (a+b)/2;
}
if (gasit)
{
long y = (a+b)/2;
while (y%5)
--y;
printf("%ld",y);
}
else
printf("-1");
return 0;
}
