Cod sursa(job #1011196)

Utilizator beyond_k7aOnutu Catalin beyond_k7a Data 16 octombrie 2013 15:48:52
Problema Factorial Scor 60
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.54 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;
	return getn(x+1,nrz-(1+nrDeCinci(x)));
	
}
int main()
{
	int p,n;


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

	n=(p==0)?1:getn(1,p);

	ofstream g("fact.out");
	g<<n;
	g.close();
	return 0;
}