Cod sursa(job #473726)

Utilizator olly2204Olly2204 olly2204 Data 31 iulie 2010 16:14:46
Problema Factorial Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.56 kb
#include <fstream>
#include <iostream>

using namespace std;



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


int main()
{

	long p;

	f >> p;

	int x1,x2,j;

	x1 = 0;
	x2 = 0;

	for (int i=0; ; i++ ) {

		j = i;

		while (j % 2 == 0 ) {
			x1++;
			j /=2;
		}

		j = i;

		while (j % 5 == 0 ) {
			x2++;
			j /=5;
		}

		if ( (x1 < x2) && (x1 == p )) {
			g << i;
			break;
		}

		if ( (x1 > x2) && (x2 == p )) {
			g << i;
			break;
		}

		if ( (x1 > p) || (x2 > p) ){
			g << -1;
		}
	}

		

	return 0;
}