Cod sursa(job #633449)

Utilizator Marin7ygsepoywepoj Marin7 Data 13 noiembrie 2011 20:02:10
Problema Factorial Scor 60
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.56 kb
#include <fstream>
using namespace std;

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

int cautare_binara(int p)
{
	int st=1,dr=100000000,mij,s,pn;
	
	while (st<dr)
	{	mij=(st+dr)/2;
		pn=5;
		s=0;
		while (pn<=mij)
		{	s+=mij/pn;
			pn*=5;	}
		if (s==p)
			return mij;
		else
			if (s<p)
				st=mij+1;
			else
				dr=mij-1;	}
	return 0;
}
int main()
{
	long long p;
	int x=1;
	f>>p;
	x=cautare_binara(p);
	x=x-x%5;
	if (p==0)
		g<<1<<'\n';
	else
		if (x)
			g<<x<<'\n';
		else
			g<<-1<<'\n';
	f.close();
	g.close();
	return 0;
}