Cod sursa(job #660528)

Utilizator andi_JunkersandiJunkers andi_Junkers Data 13 ianuarie 2012 02:18:52
Problema Factorial Scor 55
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.41 kb
#include <fstream>
using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");
int hi, lo, mij, p;

int nr_zer(int nr)
{
	unsigned y=0, c=5;
	while(nr>=c)
	{
		y+=nr/c;
		c*=5;
	}
	return y;
}

int main()
{
	f >> p;
	lo=1;
	hi=5*p;
	while(lo<hi)
	{
		mij=lo+(hi-lo)/2;
		if(nr_zer(mij)<p)
			lo=mij+1;
		else
			hi=mij-1;
	}
	if(nr_zer(lo)!=p)
		g << -1;
	else
		g << lo;
}