Cod sursa(job #523448)

Utilizator Antonius74Antonius Cezar Hegyes Antonius74 Data 18 ianuarie 2011 08:00:30
Problema Factorial Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.19 kb
#include <cstdio>
int main()
{
	
	freopen ("fact.in","r",stdin);
	freopen ("fact.out","w",stdout);
	
	int p,x=0,i=0,aux;
	scanf ("%d",&p);

	if (p<5000000)
	{
		while (i<p)
		{
		x+=5;
		aux=x;
		}
		while (aux%5==0)
		{
			aux/=5;
			i++;
		}
	}
	else
	{
		if (p<10000000)
		{
			i=4999999;
			x=20000000;
			while (i<p)
			{
				x+=5;
				aux=x;
			}
			while (aux%5==0)
			{
				aux/=5;
				i++;
			}
		}
		else
		{
			if (p<15000000)
			{
				i=9999999;
				x=40000005;
				while (i<p)
				{
					x+=5;
					aux=x;
				}
				while (aux%5==0)
				{
					aux/=5;
					i++;
				}
			}
			else
				if (p<20000000)
				{
					i=14999999;
					x=60000005;
					while (i<p)
					{
						x+=5;
						aux=x;
					}
					while (aux%5==0)
					{
						aux/=5;
						i++;
					}
				}
				else
					if (p<25000000)
					{
						i=19999999;
						x=80000010;
						while (i<p)
						{
							x+=5;
							aux=x;
						}
						while (aux%5==0)
						{
							aux/=5;
							i++;
						}
					}
		}
	}
	
	
	printf ("%d    ",i);
	
	if (i>p)
		printf ("-1 \n");
	else
		if (p==0)
			printf ("1 \n");
		else
			printf ("%d \n",x);
}