Cod sursa(job #473755)

Utilizator olly2204Olly2204 olly2204 Data 31 iulie 2010 19:34:55
Problema Factorial Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.67 kb

#include <fstream>
#include <iostream>
#include <stdio.h>

using namespace std;

ifstream f("fact.in");
ofstream g("fact.out");

int main()
{

	long p, x = 0,y = 0,z;
		
	int t = 0;


	f >> p;


	for (long  i = 1 ; i < 3000000 ; i++ ) 
	{
		z = i;

		while ( z % 2 == 0 ) 
		{
			x++;
			z = z / 2;
		}

		z = i;

		while ( z % 5 == 0 ) 
		{
			y++;
			z = z / 5;
		}


		if ((x < y) && (x == p )) 
		{
			g << i ;
			break;
			t = 1;
		}

		if ((x > y) && (y == p )) 
		{
			g << i ;
			break;
			t = 1;
		}		

		if ((x > p) || (y > p) )
		{
			break;
		}

	}

	if (t==0) {
		g << "-1";
	}




	return 0;
}