Cod sursa(job #721763)

Utilizator CameleonulVasilescu Ioan Cameleonul Data 24 martie 2012 08:27:55
Problema Factorial Scor 15
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.48 kb
#include<fstream>
using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");
int n,nr5=0,i,nr=0;
int smith(long long int n)
{
	int d=2,p;
	nr5=0;
	while(n>1)
	{
		p=0;
		while(n%d==0)
		{
			p=p+1;
			n=n/d;
		}
		if(p&&d==5) nr5+=p;
		
		d=d+1;
	}
	return nr5;
}
int main()
{
	long long unsigned p;
	f>>p;
	i=0;
	if(p)
	{
	do
	{
			i+=5;
		if(smith(i)) nr+=smith(i);
	}
	while(p>nr);
	g<<i;
	}
	else g<<1;
	f.close();
	g.close();
	return 0;
}