Problem p02722 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip> //double精度 setprecision
#include <iostream>
#include <map>
#include <numeric> //lcm
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = n - 1; i >= 0; --i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)
#define rrep1(i, n) for (int i = (n); i >= 1; --i)
#define REP(i, n, m) for (int i = (n); i < (m); ++i)
#define all(vec) (vec).begin(), (vec).end()

#define debug(vec)                                                             \
  for (auto v : vec)                                                           \
    cerr << v << " ";                                                          \
  cerr << endl;
#define debug2D(vec2D)                                                         \
  for (auto vec : vec2D) {                                                     \
    for (auto v : vec)                                                         \
      cerr << v << " ";                                                        \
    cerr << endl;                                                              \
  }
#define debugP(vec)                                                            \
  for (auto v : vec)                                                           \
    cerr << "(" << v.first << "," << v.second << ") ";                         \
  cerr << endl;
#define debug2DP(vec2D)                                                        \
  for (auto vec : vec2D) {                                                     \
    for (auto v : vec)                                                         \
      cerr << "(" << v.first << "," << v.second << ") ";                       \
    cerr << endl;                                                              \
  }

typedef long long ll;

constexpr ll INF = 1000000000; // 10^10
// const ll MOD = 998244353;
constexpr ll MOD = 1000000007;

template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  } else
    return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  } else
    return false;
}

int main() {
  ll n;
  cin >> n;

  vector<ll> enumDivisor;
  for (ll i = 1; i * i <= n - 1; ++i) {
    if ((n - 1) % i == 0) {
      enumDivisor.push_back(i);
      if (i * i != n - 1)
        enumDivisor.push_back((n - 1) / i);
    }
  }

  debug(enumDivisor)

      ll ans = enumDivisor.size() - 1;

  vector<ll> enumDivisor2;
  for (ll i = 1; i * i <= n; ++i) {
    if (n % i == 0) {
      enumDivisor2.push_back(i);
      if (i * i != n)
        enumDivisor2.push_back(n / i);
    }
  }

  debug(enumDivisor2)

      for (int d : enumDivisor2) {
    if (d == 1)
      continue;
    ll m = n;
    while (m % d == 0)
      m /= d;
    if (m % d == 1) {
      ans++;
      cerr << d << " ";
    }
  }
  cerr << endl;

  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip> //double精度 setprecision
#include <iostream>
#include <map>
#include <numeric> //lcm
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = n - 1; i >= 0; --i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)
#define rrep1(i, n) for (int i = (n); i >= 1; --i)
#define REP(i, n, m) for (int i = (n); i < (m); ++i)
#define all(vec) (vec).begin(), (vec).end()

#define debug(vec)                                                             \
  for (auto v : vec)                                                           \
    cerr << v << " ";                                                          \
  cerr << endl;
#define debug2D(vec2D)                                                         \
  for (auto vec : vec2D) {                                                     \
    for (auto v : vec)                                                         \
      cerr << v << " ";                                                        \
    cerr << endl;                                                              \
  }
#define debugP(vec)                                                            \
  for (auto v : vec)                                                           \
    cerr << "(" << v.first << "," << v.second << ") ";                         \
  cerr << endl;
#define debug2DP(vec2D)                                                        \
  for (auto vec : vec2D) {                                                     \
    for (auto v : vec)                                                         \
      cerr << "(" << v.first << "," << v.second << ") ";                       \
    cerr << endl;                                                              \
  }

typedef long long ll;

constexpr ll INF = 1000000000; // 10^10
// const ll MOD = 998244353;
constexpr ll MOD = 1000000007;

template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  } else
    return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  } else
    return false;
}

int main() {
  ll n;
  cin >> n;

  vector<ll> enumDivisor;
  for (ll i = 1; i * i <= n - 1; ++i) {
    if ((n - 1) % i == 0) {
      enumDivisor.push_back(i);
      if (i * i != n - 1)
        enumDivisor.push_back((n - 1) / i);
    }
  }

  debug(enumDivisor)

      ll ans = enumDivisor.size() - 1;

  vector<ll> enumDivisor2;
  for (ll i = 1; i * i <= n; ++i) {
    if (n % i == 0) {
      enumDivisor2.push_back(i);
      if (i * i != n)
        enumDivisor2.push_back(n / i);
    }
  }

  debug(enumDivisor2)

      for (ll d : enumDivisor2) {
    if (d == 1)
      continue;
    ll m = n;
    while (m % d == 0)
      m /= d;
    if (m % d == 1) {
      ans++;
      cerr << d << " ";
    }
  }
  cerr << endl;

  cout << ans << endl;
}