Cod sursa(job #361566)

Utilizator Cristi09Cristi Cristi09 Data 5 noiembrie 2009 20:49:36
Problema Factorial Scor 10
Compilator cpp Status done
Runda CNRV #4 Marime 0.52 kb
#include<fstream.h>
#include<values.h>
unsigned long f(unsigned long x);
int main()
{
	unsigned long p,c,bla=0,a=0,b=MAXLONG,ok=1,x;
	ifstream f("fact.in");
	f>>p;
	f.close();

	if(p==5)bla=1;

	while(ok&&!bla)
	{
	   c=(a+b)/2;

	   x=c/5;

	   if(x==p)ok=0;
	   else
		if(x<p)a=c+1;
		else b=c-1;
	}
	ofstream g("fact.out");
	if(bla)g<<-1;
	else
	if(p>5||p==0)
	{
	  if(!p)g<<1;
	  else g<<x*5-5;
	}
	else g<<x*5;
	g.close();
	return 0;
}
unsigned long f(unsigned long x)
{
   return x/5;
}