Mai intai trebuie sa te autentifici.

Cod sursa(job #2325975)

Utilizator OldpugAlex Ionescu Oldpug Data 23 ianuarie 2019 11:36:33
Problema Factorial Scor 5
Compilator cpp-64 Status done
Runda simulare_preoli Marime 0.66 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 == 1) {
    os << 0;
    return 0;
  }

  int acc = 1, two{}, five{};

  for (; p > 0; ++acc) {
    auto i = acc;

    while not_ (i % 10)
      --p,
      i /= 10;

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

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

    auto min = std::min(two, five);

    p -= min;
    two -= min;
    five -= min;
  }

  os << acc - 1;
}