Cod sursa(job #2284775)

Utilizator albertyoAlbert Mindrescu albertyo Data 17 noiembrie 2018 15:37:13
Problema Factorial Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.71 kb
#include <fstream>
using namespace std;

ifstream fin("fact.in");
ofstream fout("fact.out");

int cate(int x)
{ int ct=0;
  while(x%5==0)
    { x=x/5; ct++;}
  return ct;
}

int toate(int x)
{ int s=0,i;
  i=5;
  while(x/i!=0)
    { s=s+x/i;
      i=i*5;
    }
  return s;
}

int CB(int s,int d,int p)
{ int x;
  if(s>d) return -1;
  else { int mij;
         mij=(s+d)/2;
         x=toate(mij);
         if(p==x) return mij;
         else if(p<x) CB(s,mij-1,p);
         else CB(mij+1,d,p);
       }
}

int main()
{   int ct=0,x,s,d,p;
    fin>>p;
    s=1; d=2000000000;
    x=CB(s,d,p);
    if(x==-1) fout<<-1;
    else if(p==0) fout<<1;
    else fout<<x-(x%5);

    return 0;
}