Cod sursa(job #1011200)

Utilizator beyond_k7aOnutu Catalin beyond_k7a Data 16 octombrie 2013 15:57:59
Problema Factorial Scor 15
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.6 kb
#include<iostream>
#include<fstream>
using namespace std;
long long fact(long long x)
{
	if(x==0)
		return 1;
	return x*fact(x-1);

}
int nrDeCinci(int x)
{
	if(x%5!=0)
		return 0;
	if(x<5)
		return 0;
	return 1+nrDeCinci(x/5);
}
int getn(int x,int nrz)
{
	if(nrz == 0)
		return 5*(x-1);
	if(nrz < 0)
		return -1;
	
	while(x%5==0 && x!=0)
	{
		nrz--;
		x/=5;
	}
	nrz--;
	return getn(x+1,nrz);
	
}
int main()
{
	int p,n;
	

	ifstream f("fact.in");
	f>>p;
	f.close();

	n=(p==0)?1:getn(1,p);
	
	cout<<n;
	ofstream g("fact.out");
	g<<n;
	g.close();
	return 0;
}