Cod sursa(job #699022)

Utilizator tanduraDomnita Dan tandura Data 29 februarie 2012 17:12:49
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.49 kb
#include<fstream>
using namespace std;
int main()
{
ifstream g("fact.in");
ofstream t("fact.out");
long long p,i,j,m,x,nr,ok;
ok=1;
g>>p;
if(p==0)
   t<<1;
else
{for(i=1,j=5*p;i<=j && ok==1;)
	{m=(i+j)/2;
     x=m;
     nr=0;
     while(x!=0)
          {nr+=x/5;
		   x/=5;
		  }
     if(nr==p)
       {t<<m-m%5;
        ok=0;
       }
	 else
       {if(nr<p)
          i=m+1;
	    else
          j=m-1;
	   }
	}
 if(ok==1)
   t<<-1;
}
g.close();
t.close();
return 0;}