Cod sursa(job #571859)

Utilizator alexdmotocMotoc Alexandru alexdmotoc Data 4 aprilie 2011 20:39:19
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.63 kb
#include <iostream>
#include <fstream>
using namespace std;


int main()
{
	ifstream f ("fact.in");
	ofstream g ("fact.out");
	
	long long P , st , dr , mid , cpy , sol , aux = 4000000016;
	
	f >> P;
	
	st = 1;
	dr = 4000000015;
	
	
	while (st < dr)
	{
		sol = 0;
		
		mid = (st + dr) / 2;
		
		cpy = mid;
		
		while (cpy != 0)
		{
			cpy /= 5;
			sol += cpy;
		}
		
		
		if (sol < P)
			st = mid + 1;
		
		
		else if (sol == P)
		{
			if (mid < aux)
				aux = mid;
			
			dr = aux;
		}
		
		else dr = mid - 1;
		

	}
	

	if (aux != 4000000016)
		g << aux;
	
	else g << -1;
		
	return 0;
}