Cod sursa(job #629005)

Utilizator cremarencodianaCremarenco Diana cremarencodiana Data 2 noiembrie 2011 16:16:57
Problema Factorial Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.54 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);
	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;
}