Cod sursa(job #799610)

Utilizator cristi_berceanuFMI - Cristi Berceanu cristi_berceanu Data 19 octombrie 2012 16:32:22
Problema Factorial Scor 85
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.37 kb
#include<cstdio>

int zero(int fact)
{
	int exp=0,nr=5;
	while (nr<=fact)
		exp+=fact/nr,nr*=5;
	return exp;
}

int main()
{
	int n,i,x,y,p;
	
	freopen("fact.in","r",stdin);
	freopen("fact.out","w",stdout);
	scanf("%d",&p);
	x=0;y=1<<29;
	while (x<=y)
	{
		int z=(x+y)/2;
		if (zero(z)>=p)
			n=z,y=z-1; else
				x=z+1;
	}
printf("%d\n",n);
return 0;
}