Cod sursa(job #1355478)

Utilizator Alex1199Alex Bercea Alex1199 Data 22 februarie 2015 19:03:16
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.69 kb
#include <fstream>
using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");
int64_t p, rez, i, m, r;
int64_t zero(int n)
{
    if (!(m/n)) return 0;
    else return m/n+zero(n*5);
}
bool t=true;
int caut(int s, int d,int c)
{   if(s>d) {t=false; return s;}
   else
  {
     m=(s+d)/2;
     rez=zero(5);
    if(rez==c) return m;
    else
        {
           if(rez<c) return caut(m+1,d,c);
                 else return caut(s,m-1,c);
        }
  }
}
int main()
{
  f>>p;
  r=caut(1,400000015,p);
  m=r;
  while (zero(5)==p) m--;
  if (t){
        if (!p) g<<1;
  else
    g<<m+1;
       }
   else g<<-1;

    return 0;

}
//  400000015
//  400000015