Cod sursa(job #546919)

Utilizator andrei_stoicaStoica Andrei Florian andrei_stoica Data 5 martie 2011 17:42:48
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.42 kb
#include<fstream>
using namespace std;
ifstream in("fact.in");
ofstream out("fact.out");
int main()
{
	int p,first=1,last,mid,z=0,f,n=-1;
	in>>p;
	if(p==0)
	{
		out<<"1";
		return 0;
	}
	last=5*p;
	while(first<=last)
	{
		mid=(first+last)/2;
		z=0;
		f=mid;
		while(mid>0)
		{
			mid/=5;
			z+=mid;
		}
		if(z==p)
		{
			n=f;
			last=f-1;
		}
		if(z>p)last=f-1;
		if(z<p)first=f+1;
	}
	out<<n;
}