Pagini recente » Cod sursa (job #3189394) | Monitorul de evaluare | Cod sursa (job #629005)
Cod sursa(job #629005)
# 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);
else
return cautb(m+1,y);
}
else return -1;
}
int main()
{
freopen("factorial.in","r",stdin);
freopen("factorial.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;
}