Cod sursa(job #1391572)

Utilizator OrolesVultur Oroles Data 18 martie 2015 01:17:47
Problema Factorial Scor 80
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.67 kb
#include <iostream>
#include <fstream>

std::ifstream input("fact.in");
std::ofstream output("fact.out");

int count(int v)
{
	int contor = 0;
	int module = 0;
	int pas = 5;
	while( pas < v )
	{
		contor += v / pas;
		pas *= 5;
	}
	return contor;
}

int main(int argc, char* argv[] )
{
	unsigned int P;
	input >> P;
	unsigned int s = 1;
	unsigned int dr = 1 << 31;
	
	while ( s <= dr )
	{
		unsigned int mij = (s+dr)/2;
		int val = count(mij);
		if ( val == P )
		{
			while( count(mij) == P )
			{
				--mij;
			}
			output << ++mij;
			return 0;
		}
		else
		{
			if ( val < P )
			{
				s = mij + 1;
			}
			else
			{
				dr = mij - 1;
			}
		}
	}
	output << "imposibil";
	return 0;
}