Cod sursa(job #757722)

Utilizator VictorPVictor Padureanu VictorP Data 13 iunie 2012 02:57:01
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.4 kb
#include<stdio.h>

int main()
{
	freopen("fact.in","r",stdin);
	freopen("fact.out","w",stdout);
	
	int p,n,k,x,i;
	scanf("%d",&p);
	if(p==0) n=1;
    else n=0;        

	do
	{
		i=0;
		k=1;
		x=0;
		while(x-i+1<=p)
		{
			k *= 5;
	        x = 5*x+1;
			i++;
		}
		n += k/5;
		p -= x/5;
	}while(p>0);
	if(p==0)
	        printf("%d",n);
	else
	        printf("-1");
	return 0;
}