Cod sursa(job #629011)
| Utilizator | Data | 2 noiembrie 2011 16:19:05 | |
|---|---|---|---|
| Problema | Factorial | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.53 kb |
# include <stdio.h>
int x,y,p,n;
int nrx(int x)
{
int d=5;
int s=0;
while (x/d>=1)
{
s+=x/d;
d*=5;
}
return s;
}
int cautb(int x,int y)
{
int m;
m=(x+y)/2;
if (x<=y)
{
if (nrx(m)==p && nrx(m-1)<p) return m;
else
if (nrx(m)>=p) return cautb(x,m-1);
else
return cautb(m+1,y);
}
else return -1;
}
int main()
{
freopen("fact.in","r",stdin);
freopen("fact.out","w",stdout);
scanf("%d\n",&p);
if (p==0) printf("1\n");
else
{
x=cautb(0,5*p);
printf("%d\n",x);
}
return 0;
}
