Cod sursa(job #660721)

Utilizator raazvvannheghedus razvan raazvvann Data 13 ianuarie 2012 12:34:54
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.43 kb
#include <fstream>

using namespace std;

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

int p,lo,hi,mij;

int rez(int n)
{
	int a=0,b=5;
	while(n>=b)
	{
		a+=n/b;
		b*=5;
	}
	return a;
}

void caut()
{
	lo = 1, hi = 5*p;
	while(lo <= hi ) 
	{
		mij = lo+(hi-lo)/2; 
		if(rez(mij) < p) 
			lo = mij+1; 
		
		else hi = mij-1; 
	}
}

int main()
{
	f>>p;
	caut();
	if(rez(lo) != p)
	g << -1; 
	else g << lo;
}