Cod sursa(job #1152906)

Utilizator georgeUUngureanu George georgeU Data 25 martie 2014 08:51:31
Problema Factorial Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.57 kb
#include <fstream>

using namespace std;
ifstream fin ("factorial.in");
ofstream fout ("factorial.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 cauta (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 cauta (st,mij-1);
  return cauta(mij+1,dr);

}
int main()
{ fin >>p;
  n=cauta(1,2000000000);
  if (n==-1) fout <<n;
  else while (n%5!=0)
        n--;
  fout <<n;


    return 0;
}