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

#pragma region template
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD = 1e9 + 7, MAX = 1e18, larg = 1e5, INF = -1e9;
long long A, B, C, D, E, F, G, H, I, J, K, L, N, M, O, P, Q, S, T, U, V, W, x,
    y, z;
long long max_value = INF, max_index = -1;
typedef long long ll;
typedef pair<ll, ll> Pa;

template <std::int_fast64_t Modulus> class modint {
  using u64 = std::int_fast64_t;

public:
  u64 a;
  constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
  constexpr u64 &value() noexcept { return a; }
  constexpr const u64 &value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= Modulus) {
      a -= Modulus;
    }
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += Modulus;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  constexpr modint &operator/=(modint rhs) noexcept {
    u64 exp = Modulus - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
};
#pragma endregion

vector<ll> divisor(ll num) {
  vector<ll> vec;
  for (ll i = 1; i * i <= num; i++) {
    if (num % i == 0) {
      vec.push_back(i);
      if (i * i != num)
        vec.push_back(num / i);
    }
  }
  sort(begin(vec), end(vec));
  return vec;
}

int main() {
  cin >> N;
  vector<ll> vec = divisor(N - 1);
  int count = vec.size() - 1;
  vector<ll> vec2 = divisor(N);
  for (int i = 1; i < vec2.size(); i++) {
    ll curr = N;
    while (curr >= vec2[i]) {
      if (curr % vec2[i] == 0)
        curr /= vec2[i];
      else
        curr %= vec2[i];
    }
    if (curr == 1)
      count++;
  }

  cout << count;
}


Error: WA

Fixed submission:

#pragma region template
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD = 1e9 + 7, MAX = 1e18, larg = 1e5, INF = -1e9;
long long A, B, C, D, E, F, G, H, I, J, K, L, N, M, O, P, Q, S, T, U, V, W, x,
    y, z;
long long max_value = INF, max_index = -1;
typedef long long ll;
typedef pair<ll, ll> Pa;

template <std::int_fast64_t Modulus> class modint {
  using u64 = std::int_fast64_t;

public:
  u64 a;
  constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
  constexpr u64 &value() noexcept { return a; }
  constexpr const u64 &value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= Modulus) {
      a -= Modulus;
    }
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += Modulus;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  constexpr modint &operator/=(modint rhs) noexcept {
    u64 exp = Modulus - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
};
#pragma endregion

bool flag[1000] = {false};

// 素数を求める
vector<ll> prime_factor(ll num) {
  vector<ll> vec;
  ll a = 2;
  while (num >= a * a) {
    if (num % a == 0) {
      vec.push_back(a);
      num /= a;
      flag[a] = true;
    } else {
      a++;
    }
  }
  vec.push_back(num);
  return vec;
}

int main() {
  cin >> N;
  vector<ll> vec = prime_factor(N - 1);
  int count = 1;
  ll prev = vec[0];
  ll sum = 1;
  rep(i, vec.size() - 1) {
    if (prev == vec[i + 1]) {
      count++;
    } else {
      prev == vec[i + 1];
      sum *= (count + 1);
      count = 1;
    }
  }
  sum *= (count + 1);
  int prime[25] = {2,  3,  5,  7,  11, 13, 17, 19, 23, 29, 31, 37, 41,
                   42, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97};
  for (int i = 0; i < 25; i++) {
    if (flag[prime[i]])
      continue;
    if (prime[i] > N)
      continue;
    int curr = N;
    while (curr > prime[i]) {
      if (curr % prime[i] == 0)
        curr /= prime[i];
      else
        curr %= prime[i];
    }
    if (curr == 1)
      sum++;
  }
  cout << sum;
}