Cod sursa(job #572039)

Utilizator tudorsTudor Siminic tudors Data 4 aprilie 2011 23:06:07
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.44 kb
#include <fstream>
using namespace std;
int p,st,dr,mij;
ifstream f("fact.in");
ofstream g("fact.out");
int zero(int x)
{
	int s,ps;
	s=0;
	ps=5;
	while (x/ps!=0)
	{
		s+=(x/ps);
		ps*=5;
	}
	return s;
}
int main()
{
	f>>p;
	st=1;
	dr=10*p;
	while (st<=dr)
	{
		mij=st+(dr-st)/2;
		if (zero(mij)>=p)
			dr=mij-1;
		else
			st=mij+1;
	}
	if (zero(st)==p)
		g<<st;
	else
		g<<-1;
	f.close();
	g.close();
	return 0;
}