Cod sursa(job #6199)

Utilizator skyelHighScore skyel Data 18 ianuarie 2007 07:53:29
Problema Factorial Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.39 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;
	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;
	}