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

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, l, r) for (ll i = (l); i < (r); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FOR(i, 1, n + 1)
#define RFOR(i, l, r) for (ll i = (l); i >= (r); --i)
#define RREP(i, n) RFOR(i, n - 1, 0)
#define RREPS(i, n) RFOR(i, n, 1)
#define pb push_back
#define eb emplace_back
#define SZ(x) ((ll)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
template <class T = ll> using V = vector<T>;
template <class T = ll> using VV = V<V<T>>;
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
inline void Yes(bool b = true) { cout << (b ? "Yes" : "No") << '\\n'; }
inline void YES(bool b = true) { cout << (b ? "YES" : "NO") << '\\n'; }
inline void err(bool b = true) {
  if (b) {
    cout << -1 << '\\n';
    exit(0);
  }
}
template <class T> inline void fin(bool b = true, T e = 0) {
  if (b) {
    cout << e << '\\n';
    exit(0);
  }
}
template <class T> T Roundup_div(T x, T y) { return (x + (y - 1)) / y; }
const ll INF = 1e18;
template <typename T> T pow(T a, long long n, T e = 1) {
  T ret = e;
  while (n) {
    if (n & 1)
      ret *= a;
    a *= a;
    n >>= 1;
  }
  return ret;
}

// Prime Factorization(素因数分解)
map<ll, int> divisor; // 約数を入れるmap
void PF(ll n) {
  divisor.clear();
  ll c = n;
  for (int i = 2; i <= sqrt(n); i++) {
    while (c % i == 0) {
      divisor[i]++;
      c /= i;
    }
  }
  if (c != 1)
    divisor[c]++;
  return;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n;
  cin >> n;
  ll res = 1;
  PF(n - 1);
  for (auto v : divisor)
    res *= (v.second + 1);
  for (int i = 2; i <= sqrt(n); i++) {
    ll c = n;
    if (n % i)
      continue;
    while (!(c % i))
      c /= i;
    if ((c % i) == 1)
      res++;
    c = n;
    ll j = n / i;
    if (i == j)
      continue;
    while (!(c % j))
      c /= j;
    if ((c % j) == 1)
      res++;
  }
  cout << res << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, l, r) for (ll i = (l); i < (r); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FOR(i, 1, n + 1)
#define RFOR(i, l, r) for (ll i = (l); i >= (r); --i)
#define RREP(i, n) RFOR(i, n - 1, 0)
#define RREPS(i, n) RFOR(i, n, 1)
#define pb push_back
#define eb emplace_back
#define SZ(x) ((ll)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
template <class T = ll> using V = vector<T>;
template <class T = ll> using VV = V<V<T>>;
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
inline void Yes(bool b = true) { cout << (b ? "Yes" : "No") << '\\n'; }
inline void YES(bool b = true) { cout << (b ? "YES" : "NO") << '\\n'; }
inline void err(bool b = true) {
  if (b) {
    cout << -1 << '\\n';
    exit(0);
  }
}
template <class T> inline void fin(bool b = true, T e = 0) {
  if (b) {
    cout << e << '\\n';
    exit(0);
  }
}
template <class T> T Roundup_div(T x, T y) { return (x + (y - 1)) / y; }
const ll INF = 1e18;
template <typename T> T pow(T a, long long n, T e = 1) {
  T ret = e;
  while (n) {
    if (n & 1)
      ret *= a;
    a *= a;
    n >>= 1;
  }
  return ret;
}

// Prime Factorization(素因数分解)
map<ll, int> divisor; // 約数を入れるmap
void PF(ll n) {
  divisor.clear();
  ll c = n;
  for (int i = 2; i <= sqrt(n); i++) {
    while (c % i == 0) {
      divisor[i]++;
      c /= i;
    }
  }
  if (c != 1)
    divisor[c]++;
  return;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n;
  cin >> n;
  ll res = 1;
  PF(n - 1);
  for (auto v : divisor)
    res *= (v.second + 1);
  res--;
  for (int i = 1; i <= sqrt(n); i++) {
    int c = n;
    if (i == 1)
      goto F;
    if (n % i)
      continue;
    while (!(c % i))
      c /= i;
    if ((c % i) == 1)
      res++;
  F:;
    if (i * i != n) {
      c = n;
      int j = n / i;
      while (!(c % j))
        c /= j;
      if ((c % j) == 1)
        res++;
    }
  }
  cout << res << endl;
}