Cod sursa(job #703372)

Utilizator cristi103tiron cristian cristi103 Data 2 martie 2012 12:04:00
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.57 kb
#include<fstream>
using namespace std;
int main()
{
ifstream f("fact.in");
ofstream g("fact.out");
long long p,i,j,m,x,nr,ok;
ok=1;
f>>p;
if(p==0)
   g<<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)
       {
              g<<m-m%5;
        ok=0;
       }
	 else
       {
             if(nr<p)
          i=m+1;
	    else
          j=m-1;
	   }
	}
 if(ok==1)
   g<<-1;
}
f.close();
g.close();
return 0;}