Cod sursa(job #244105)

Utilizator b0by_ceausuCeausu Bogdan Constantin b0by_ceausu Data 14 ianuarie 2009 16:39:33
Problema Factorial Scor 60
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.51 kb
#include <fstream.h>
ifstream f("fact.in");
ofstream g("fact.out");
long li,ls,m,nr,z,p;
int main ()
{
f>>p;
if (p==0)
   g<<1<<'\n';
   else
   {
li=1;
ls=100000000;
while (li<=ls)
	  {
	  m=(li+ls)/2;
	  nr=0;
	  z=5;
	  while (z<=m)
			{
			nr=nr+m/z;
			z=z*5;
			}
	  if (nr==p)
		  break;
		  else
		  if (nr>p)
			 ls=m-1;
			 else
			 li=m+1;
	  }
if (li>ls)
   g<<"-1"<<'\n';
   else
   {
   while (m%5!=0)
		 m--;
   g<<m<<'\n';
   }}
f.close ();
g.close ();
return 0;
}