Cod sursa(job #2325997)

Utilizator OldpugAlex Ionescu Oldpug Data 23 ianuarie 2019 11:47:57
Problema Factorial Scor 20
Compilator cpp-64 Status done
Runda simulare_preoli Marime 0.54 kb
#ifdef INFOARENA
#include <fstream>
std::ifstream is{"fact.in"};
std::ofstream os{"fact.out"};
#else
#include <iostream>
#define is std::cin
#define os std::cout
#endif // INFOARENA

#define not_(expr) (!(expr))

int main() {
  int p;
  is >> p;

  if (!p) {
    os << 1;
    return 0;
  }

  int acc = 1, two = p, five = p;

  for (; five > 0 || two > 0; ++acc) {
    auto i = acc;

    while not_ (i & 1)
      --two,
      i >>= 1;

    while not_ (i % 5)
      --five,
      i /= 5;
  }

  os << acc - 1;
}