Cod sursa(job #264694)

Utilizator Radu_BumbaceaRadu Bumbacea Radu_Bumbacea Data 22 februarie 2009 16:37:54
Problema Factorial Scor 85
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.42 kb
#include <stdio.h>

int main()
{
	int n,p,q,k,t;
	int a[40];
	freopen("fact.in","r",stdin);
	freopen("fact.out","w",stdout);
	scanf("%d",&p);
	q=1;k=0;n=0;
	while ((q-1)/4<=p)
	{
		q=q*5;
		k=k+1;
	}
	q=q/5;k=k-1;
	//q=25;k=2;p=10
	for (int i=k;i>=1;i=i-1)
	{
		t=(q-1)/4;
		a[i]=p/t;
		p=p-(t*a[i]);
		q=q/5;
	}
	for (int j=k;j>=1;j=j-1)
	{
		n=n*5+a[j];
	}
	n=n*5;
	printf("%d",n);
	return 0;
}