Cod sursa(job #143242)

Utilizator Andrei_ScorpioAndreiana Andrei Daniel Andrei_Scorpio Data 26 februarie 2008 08:37:28
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.44 kb
#include<fstream.h>
long mij,mij1,n,nr,nr2,p=0,u=2000000000,gasit;
ifstream f("fact.in");
ofstream g("fact.out");
int main()
{
f>>nr;
if(nr==0)
	g<<1;
else
	{
	while(p<=u && gasit==0)
	{
	mij=(p+u)/2;
	nr2=0;
	mij1=mij;
	while(mij1>0)
		{
		nr2+=mij1/5;
		mij1/=5;
		}
	if(nr2<nr)
		p=mij+1;
	else
		if(nr2>nr)
			u=mij-1;
		else
			gasit=1;
	}
if(gasit==1)
	g<<mij-mij%5;
else
	g<<-1;
	}
g.close();
return 0;
}