Cod sursa(job #521074)

Utilizator Antonius74Antonius Cezar Hegyes Antonius74 Data 11 ianuarie 2011 08:18:50
Problema Factorial Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.46 kb
#include <cstdio>
int main()
{

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

}