Cod sursa(job #10815)

Utilizator free2_do_rhymesGet a Life free2_do_rhymes Data 29 ianuarie 2007 16:25:05
Problema Factorial Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.53 kb
#include <fstream.h>
long int p,n,i,h=0,l=0,k=0;
int main()
{
	ifstream f("fact.in");
	ofstream g("fact.out");
	f>>n;
	while(n!=0)
	{
		p=p+5;
		h=0;
		k=0;
		if(p%5==0 && p%10!=0)
		{
			i=p;
			while(p%5==0)
			{
				h++;
				p=p/5;
			}
			p=i;
		}
		else
		{
			if(p%10==0)
			{
				i=p;
				while(p%10==0)
				{
					k++;
					p=p/10;
				}
				while(p%5==0)
				{
					k++;
					p=p/5;
				}
				p=i;
			}

		}
		if(h!=0)

			n=n-h;
		else
			if(k!=0)
				n=n-k;
	}
	g<<p;
	return 0;

}