Cod sursa(job #629094)

Utilizator stay_awake77Cangea Catalina stay_awake77 Data 2 noiembrie 2011 17:16:17
Problema Factorial Scor 95
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.65 kb
#include <fstream>

#define INF (1<<30)

using namespace std;

int P, Rez;
bool gasit;

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

inline int minim( int a, int b )
{
	return (a<b) ? a : b;
}

inline int Nr0( int x )
{
	int R = 0, Pow = 5;
	while( x/Pow > 0 )
	{
		R += x/Pow;
		Pow *= 5;
	}
	
	return R;
}

inline int BS( int St, int Dr )
{
	if( St <= Dr )
	{
		int M = St + (Dr-St)/2;
		
		if( Nr0( M ) == P && Nr0( M-1 ) < P ) return M;
		else if( Nr0( M ) >= P ) return BS( St, M-1 );
		else return BS( M+1, Dr );
	}
	else return -1;
}

int main()
{
	in >> P;
	out << BS( 1, INF ) << '\n';
	
	return 0;
}