Problem p02548 (C++) — buggy submission, verdict: Runtime Error

#define errOut(s)                                                              \\
  { std::cerr << __LINE__ << ":" << #s << ":" << (s) << std::endl; }

#include <bits/stdc++.h>

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Weverything"
// #include <boost/multi_array.hpp>
// #include <boost/optional.hpp>
// #include <boost/range/adaptors.hpp>
// #include <boost/range/algorithm.hpp>
// #include <boost/range/irange.hpp>
#pragma clang diagnostic pop

using namespace std;
template <size_t N, size_t MaxPrimeSize> struct primes_t {
  constexpr static size_t maxPrimeSize = MaxPrimeSize;
  constexpr primes_t() : primes(), count(), notSieves() {
    primes[count++] = 2;
    notSieves[0] = notSieves[1] = true;
    for (int i = 2; i < N; i++) {
      if (notSieves[i]) {
        continue;
      }
      primes[count++] = i;
      for (int64_t j = 2; i * j < N; j++) {
        notSieves[i * j] = true;
      }
    }
  }
  int64_t primes[MaxPrimeSize];
  int count;

private:
  bool notSieves[N];
};

static auto primes = primes_t<1000001, 1000000>{};

int64_t solve(int64_t const n) {
  int64_t ret = 0;
  for (int c = 1; c < n - 1; c++) {
    int64_t nn = n - c;
    int64_t cnt = 1;
    int64_t mx = int64_t(ceil(sqrt(nn * 1.0)));
    for (int i = 0; nn != 1; i++) {
      int64_t const p = primes.primes[i];
      if (nn % p != 0) {
        if (p > mx) {
          cnt *= 2;
          break;
        }
        continue;
      }
      int j = 0;
      while (nn % p == 0) {
        nn /= p;
        j++;
      }
      mx = int64_t(ceil(sqrt(nn * 1.0)));
      if (j > 0) {
        cnt *= (j + 1);
      }
    }
    ret += cnt;
  }
  ret++;
  return ret;
}

int main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  int64_t n;
  std::cin >> n;
  auto const res = solve(n);
  std::cout << res << std::endl;
  return 0;
}


Error: 0

Fixed submission:

#define errOut(s)                                                              \\
  { std::cerr << __LINE__ << ":" << #s << ":" << (s) << std::endl; }

#include <bits/stdc++.h>

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Weverything"
// #include <boost/multi_array.hpp>
// #include <boost/optional.hpp>
// #include <boost/range/adaptors.hpp>
// #include <boost/range/algorithm.hpp>
// #include <boost/range/irange.hpp>
#pragma clang diagnostic pop

using namespace std;
template <size_t N, size_t MaxPrimeSize> struct primes_t {
  constexpr static size_t maxPrimeSize = MaxPrimeSize;
  constexpr primes_t() : primes(), count(), notSieves() {
    primes[count++] = 2;
    notSieves[0] = notSieves[1] = true;
    for (int i = 2; i < N; i++) {
      if (notSieves[i]) {
        continue;
      }
      primes[count++] = i;
      for (int64_t j = 2; i * j < N; j++) {
        notSieves[i * j] = true;
      }
    }
  }
  int64_t primes[MaxPrimeSize];
  int count;

private:
  bool notSieves[N];
};

static auto primes = primes_t<1000001, 1000000>{};

int64_t solve(int64_t const n) {
  int64_t ret = 0;
  for (int c = 1; c < n - 1; c++) {
    int64_t nn = n - c;
    int64_t cnt = 1;
    for (int i = 0;; i++) {
      int64_t const p = primes.primes[i];
      if (p > nn) {
        break;
      }
      int j = 0;
      while (nn % p == 0) {
        nn /= p;
        j++;
      }
      if (j > 0) {
        cnt *= (j + 1);
      }
    }
    ret += cnt;
  }
  ret++;
  return ret;
}

int main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  int64_t n;
  std::cin >> n;
  auto const res = solve(n);
  std::cout << res << std::endl;
  return 0;
}