Cod sursa(job #6216)

Utilizator skyelHighScore skyel Data 18 ianuarie 2007 15:11:59
Problema Factorial Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.44 kb
#include<fstream.h>
#define input "fact.in"
#define output "fact.out"



int main()
	{
	long h,x,n;
	int gr;
	ifstream fin(input);
	ofstream fout(output);
	fin>>n;
	x=n;
	h=1;
	gr=0;
	if(n==0)
		fout<<"0/n";
	else
		while(h*5+1<=n)
			{
			h=(h*5)+1;
			gr++;
			}
		if(n+gr>=(h*5)+1)
			fout<<"-1"<<"\n";
		else
			{
			while(h!=1)
				{
				x-=(x/h);
				h--;
				h=h/5;
				}
			fout<<x*5<<"\n";
			}
	return 0;
	}