Cod sursa(job #1205227)

Utilizator stoicatheodorStt sas stoicatheodor Data 5 iulie 2014 18:37:34
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.79 kb
#include <fstream>
using namespace std;
ifstream in ("fact.in");
ofstream out ("fact.out");
int p,n;
int putere5(long x)
    {
        long y,e;
        y=5; e=0;
        while (y<=x)
          {
              e=e+x/y;
              y=5*y;
          }
   return e;
}
long cautare (long st, long dr)
    { int mij,nrz;
      if (st>dr) return -1;
      mij=(st+dr)/2;
      nrz=putere5(mij);
      if (nrz==p) return mij;
      if (p<nrz) return cautare (st,mij-1);
      return cautare(mij+1,dr);
}
int main()
{
      in >>p;
      if (p==0)
            {
                out<<"1";
                return 0;
            }
      n=cautare(1,2000000000);
      if (n==-1) out <<n;
      else
        while (n%5!=0)
            n--;
      out <<n;
      return 0;
}