Cod sursa(job #1919427)

Utilizator SenibelanMales Sebastian Senibelan Data 9 martie 2017 19:24:31
Problema Factorial Scor 85
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.6 kb
#include <fstream>

using namespace std;

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

const int oo = 2000000000;
int P;
int sol = oo + 1;

bool Works(int n){
  int zr = 0;
  while(n){
    zr += n / 5;
    n /= 5;
  }
  if(zr >= P)
    return 1;
  return 0;
}

void BinarySearch(int left, int right){
  int mid;
  while(left <= right){
    mid = (left + right) / 2;
    if(Works(mid)){
      sol = mid;
      right = mid - 1;
    }
    else
      left = mid + 1;
  }
}

int main(){
  in >> P;
  BinarySearch(0, oo);
  if(sol == oo + 1)
    out << -1 << "\n";
  else
    out << sol << "\n";
  return 0;
}