Cod sursa(job #1166417)

Utilizator LarryIulian Dutu Larry Data 3 aprilie 2014 16:12:53
Problema Factorial Scor 25
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.51 kb
#include <fstream>
using namespace std;

int main()
{
	unsigned P,z=0,i,a,d=0,e=0;
	ifstream f("fact.in");
	f>>P;
	f.close();
	for(i=1;z<P;i++)
	{
		a=i;
		while(a%10==0)
		{
			z++;
			a/=10;
		}
		while(a%5==0)
		{
			d++;
			a/=5;
		}
		while(a%2==0)
		{
			e++;
			a/=2;
		}
		if(d>=e)
		{
			z+=e;
			d-=e;
			e=0;
		}
		else
		{
			z+=d;
			e-=d;
			d=0;
		}
	}
	ofstream g("fact.out");
	if(P==0)
		i=2;
	if(z==P)
		g<<i-1;
	else
		g<<-1;
	g.close();
	return 0;
}