Cod sursa(job #133175)

Utilizator AndreyPAndrei Poenaru AndreyP Data 7 februarie 2008 20:03:35
Problema Factorial Scor 60
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.38 kb
#include<stdio.h>
int main()
{
	unsigned int p,n=0,a,p1=0,n1;
	freopen("fact.in","r",stdin);
	freopen("fact.out","w",stdout);
	scanf("%u",&p);
	if(p==0)
		printf("1\n");
	else
	{
		while(p1<p)
		{
			n+=5;
			a=0;
			n1=n;
			while(n1%5==0)
			{
				n1=n1/5;
				a++;
			}
			p1+=a;
		}
		if(p1==p)
			printf("%u\n",n);
		else
			printf("-1\n");
	}
	return 0;
}