alexjercan/bugnet huggingface dataset:
Problem p02722 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define endl "\\n"
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
ll mod = 1e9 + 7;

int main() {
  fast
      // #ifndef ONLINE_JUDGE
      // freopen("input.txt","r",stdin);
      // freopen("output.txt","w",stdout);
      // #endif
      set<ll>
          s;
  ll n;
  cin >> n;
  s.insert(n);
  for (ll i = 2; i * i <= n; i++) {
    ll x = n;
    while (x % i == 0) {
      x /= i;
    }
    if (x % i == 1)
      s.insert(i);
  }
  n -= 1;
  s.insert(n);
  for (ll i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      s.insert(n / i);
      s.insert(i);
    }
  }
  ll count = 0;
  // for(auto it:s)
  //  cout<<it<<endl;
  if (n == 1)
    cout << 1 << endl;
  else
    cout << s.size();

  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define endl "\\n"
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
ll mod = 1e9 + 7;

int main() {
  fast
#ifndef ONLINE_JUDGE
      freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  set<ll> s;
  ll n;
  cin >> n;
  s.insert(n);
  for (ll i = 2; i * i <= n; i++) {
    if (n % i == 0) {

      if (n / i == i) {
        s.insert(n / i);
      }

      else {
        ll x = n / i;
        if (x % i == 1)
          s.insert(i);
      }
      // s.insert(n/i);
    }
  }
  n -= 1;
  s.insert(n);
  for (ll i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      s.insert(n / i);
      s.insert(i);
    }
  }
  ll count = 0;
  // for(auto it:s)
  //  cout<<it<<endl;
  cout << s.size();

  return 0;
}
Problem p02722 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

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

int main() {
  ll n;
  cin >> n;
  auto p = divisor(n);
  auto q = divisor(n - 1);
  set<ll> s;
  rep(i, p.size()) s.insert(p[i]);
  rep(i, q.size()) s.insert(q[i]);
  ll cnt = 0;
  for (ll t : s) {
    if (t == 1)
      continue;
    ll tmp = n;
    while (tmp > 0) {
      if (tmp == 1) {
        cnt++;
        break;
      }
      if (tmp % t == 0)
        tmp /= t;
      else {
        tmp %= t;
        if (tmp == 1)
          cnt++;
        break;
      }
    }
  }
  cout << cnt << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

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

int main() {
  ll n;
  cin >> n;
  auto p = divisor(n);
  auto q = divisor(n - 1);
  set<ll> s;
  rep(i, p.size()) s.insert(p[i]);
  rep(i, q.size()) s.insert(q[i]);
  ll cnt = 0;
  for (ll t : s) {
    if (t == 1)
      continue;
    ll tmp = n;
    if (tmp % t == 1)
      cnt++;
    else
      while (tmp > 0) {
        if (tmp == 1) {
          cnt++;
          break;
        }
        if (tmp % t == 0)
          tmp /= t;
      }
  }
  cout << cnt << endl;
  return 0;
}
Problem p02722 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i <= (n); ++i)

using namespace std;
using ll = long long;
using P = pair<int, int>;

vector<ll> Yakusu(ll n) {
  vector<ll> res;

  for (ll i = 1; i * i <= n; ++i) {
    if (n % i != 0)
      continue;
    res.push_back(i);
    if (i * i != n)
      res.push_back(n / i);
  }
  return res;
}

int main() {
  ll n;
  cin >> n;
  int ans = 0;

  for (ll x : Yakusu(n)) {
    if (x == 1)
      continue;
    ll tmp = n;
    while (tmp % x == 0)
      tmp /= x;

    tmp %= x;
    if (tmp == 1)
      ++ans;
  }
  ans += Yakusu(n - 1).size() - 1;

  cout << ans << endl;
  return 0;
}

Error: -8

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i <= (n); ++i)

using namespace std;
using ll = long long;
using P = pair<int, int>;

vector<ll> Yakusu(ll n) {
  vector<ll> res;

  for (ll i = 1; i * i <= n; ++i) {
    if (n % i != 0)
      continue;
    res.push_back(i);
    if (i * i != n)
      res.push_back(n / i);
  }
  return res;
}

int main() {
  ll n;
  cin >> n;
  int ans = 0;

  for (ll x : Yakusu(n)) {
    if (x == 1)
      continue;
    ll tmp = n;
    while (tmp %= 0)
      tmp /= x;

    tmp %= x;
    if (tmp == 1)
      ++ans;
  }
  ans += Yakusu(n - 1).size() - 1;

  cout << ans << endl;
  return 0;
}
Problem p02722 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vin = vector<int>;
using vll = vector<long long>;
using vdo = vector<double>;
using vvin = vector<vector<int>>;
using vvll = vector<vector<long long>>;
using vvdo = vector<vector<double>>;
using vstr = vector<string>;
using vvstr = vector<vector<string>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define _GLIBCXX_DEBUG
int main() {
  ll n;
  cin >> n;
  if (n == 2)
    cout << 1 << endl;
  else {
    ll sum = 2;
    for (ll i = 2; i * i <= n; i++) {
      if (n % i == 1) {
        // n-1の約数の個数を数える
        if (i * i == n - 1)
          sum++;
        else
          sum += 2;
      }
      ll x = n;
      if (n % i == 0) {
        while (x % i == 0) {
          x /= i;
        }
        if (x % i == 1)
          sum++;
      }
    }
    cout << sum << endl;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vin = vector<int>;
using vll = vector<long long>;
using vdo = vector<double>;
using vvin = vector<vector<int>>;
using vvll = vector<vector<long long>>;
using vvdo = vector<vector<double>>;
using vstr = vector<string>;
using vvstr = vector<vector<string>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define _GLIBCXX_DEBUG
int main() {
  ll n;
  cin >> n;
  ll sum = 0;
  for (ll i = 2; i <= n; i++) {
    if (n % i == 1)
      sum++;
    ll x = n;
    if (n % i == 0) {
      while (x % i == 0) {
        x = x / i;
      }
      if (x % i == 1)
        sum++;
    }
  }
  cout << sum << endl;
}
Problem p02722 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bits/stdc++.h>
#include <iostream>
#include <vector>

using namespace std;

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

  long long int ans = 0;

  long long int num = n;

  for (long long int i = 1; i * i <= n - 1; i++) {

    if ((n - 1) % i == 0) {
      ans += 1;
      if ((n - 1) / i != i) {
        ans += 1;
      }
    }
  }

  for (long long int i = 2; i * i <= n; i++) {
    num = n;
    if (n % i == 0) {
      while (num % i == 0) {
        num /= i;
      }
      if (num % i == 1) {
        ans++;
      }
    }
  }

  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <bits/stdc++.h>
#include <iostream>
#include <vector>

using namespace std;

vector<long long int> enum_div(long long int n) {
  std::vector<long long int> ret;
  for (long long int i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i != 1 && i * i != n) {
        ret.push_back(n / i);
      }
    }
  }
  return ret;
}

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

  long long int ans = 1;

  vector<int> x(n);

  long long int num = n - 1;

  for (long long int i = 2; i <= n - 1; i++) {
    while (num % i == 0) {
      x.at(i)++;
      num /= i;
    }
  }
  for (long long int i = 2; i <= n - 1; i++) {
    ans *= x.at(i) + 1;
  }
  int res = 0;
  vector<long long int> r = enum_div(n);
  for (auto i : r) {
    if ((n / i) % i == 1)
      res++;
  }

  if (res > 0) {
    res--;
  }

  cout << ans + res + 1 << endl;
}
Problem p02722 (C++) — buggy submission, verdict: Time Limit Exceeded

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
int main() {
  int64_t cnt = 0;
  int64_t n, p, k;
  cin >> n;
  p = n;
  for (int64_t i = 1; i <= sqrt(n); i++) {
    if (i == 1) {
      cnt++;
      continue;
    }
    while (n % i == 0) {
      n = n / i;
      if (n % i == 1)
        cnt++;
    }
    n = p;
  }
  // cout<<cnt<<" "<<sqrt(n)<<endl;
  for (int64_t i = 1; i <= sqrt(p - 1); i++) {
    if (i == 1 && (p - 1) != 1) {
      cnt++;
      continue;
    }
    if ((p - 1) % i == 0 && (p - 1) != 1) {
      k = (p - 1) / i;
      if (i == k) {
        cnt++;
      } else
        cnt += 2;
    }
  }
  cout << cnt;
}


Error: TLE

Fixed submission:

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
int main() {
  queue<int64_t> que1, que2;
  int64_t n, sum = 0, k;
  cin >> n;
  k = n;
  for (int64_t i = 2; i <= n; i++) {
    while (n % i == 0) {
      n = n / i;
      if (n % i == 1)
        que1.push(i);
    }
  }
  for (int64_t i = 2; i <= (k - 1); i++) {
    if ((k - 1) % i == 0) {
      que2.push(i);
    }
  }
  sum = que1.size() + que2.size();
  cout << sum;
}
Problem p02722 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 7;
const int M = 1e6 + 7;
const int INF = 1e9 + 7;
ll ans = 0, n;
map<ll, bool> m1;
void check(ll x) {
  if (x == 1)
    return;
  ll m = n;
  while (m % x == 0)
    m = m / x;
  m = m % x;
  if (m == 1) {
    if (!m1[x]) {
      ans++;
      m1[x] = 1;
    }
  }
}
void judge(ll x) {
  for (ll i = 1; i * i <= x; i++) {
    if (x % i == 0) {
      check(i);
      check(x / i);
    }
  }
}

int main() {

  cin >> n;
  judge(n - 1);
  judge(n);
  cout << ans << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 7;
const int M = 1e6 + 7;
const int INF = 1e9 + 7;
ll ans = 0, n;
map<ll, bool> m1;
void check(ll x) {
  if (x == 0)
    return;
  ll m = n;
  while (m % x == 0)
    m = m / x;
  m = m % x;
  if (m == 1) {
    if (!m1[x]) {
      ans++;
      m1[x] = 1;
    }
  }
}
void judge(ll x) {
  for (ll i = 1; i * i <= x; i++) {
    if (x % i == 0) {
      check(i);
      check(x / i);
    }
  }
}

int main() {

  cin >> n;
  judge(n - 1);
  judge(n);
  cout << ans << endl;
  return 0;
}
Problem p02722 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long int64;
int main() {
  int64 n;
  cin >> n;
  set<int64> ret;
  for (int64 i = 1; i * i <= (n - 1); i++) {
    if ((n - 1) % i == 0) {
      if (i != 1)
        ret.insert(i);
      if (((n - 1) / i) != 1)
        ret.insert((n - 1) / i);
    }
  }
  vector<int64> F;
  for (int64 i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      if (i != 1)
        F.push_back(i);
      if ((n / i) != i)
        F.push_back(n / i);
    }
  }

  for (int64 f : F) {
    for (int64 p = f;; p *= f) {
      if ((n / p) % f == 1)
        ret.insert(f);
      if ((n / p) % f)
        break;
    }
  }
  cout << ret.size() << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long int64;
int main() {
  int n;
  cin >> n;
  set<int64> ret;
  for (int i = 1; i * i <= (n - 1); i++) {
    if ((n - 1) % i == 0) {
      if (i != 1)
        ret.insert(i);
      if (((n - 1) / i) != 1)
        ret.insert((n - 1) / i);
    }
  }
  vector<int> F;
  for (int i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      if (i != 1)
        F.push_back(i);
      if ((n / i) != i)
        F.push_back(n / i);
    }
  }

  for (int f : F) {
    for (int p = f;; p *= f) {
      if ((n / p) % f == 1)
        ret.insert(f);
      if ((n / p) % f)
        break;
    }
  }
  cout << ret.size() << endl;
  return 0;
}
Problem p02722 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
using ll = long long;

bool check(ll n, ll a) {
  ll c = n;
  while (c >= a) {
    if (c % a == 0)
      c /= a;
    else
      c %= a;
  }
  return (c == 1);
}

int main() {
  ll n;
  cin >> n;
  vector<ll> v;
  v.push_back(n);
  if (n != 2)
    v.push_back(n - 1);
  for (ll i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      v.push_back(i);
      v.push_back(n / i);
    }
  }
  for (ll i = 2; i * i <= n - 1; i++) {
    if ((n - 1) % i == 0) {
      v.push_back(i);
      v.push_back((n - 1) / i);
    }
  }
  set<int> s;
  for (auto x : v) {
    if (check(n, x))
      s.insert(x);
  }
  cout << s.size() << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
using ll = long long;

bool check(ll n, ll a) {
  ll c = n;
  while (c >= a) {
    if (c % a == 0)
      c /= a;
    else
      c %= a;
  }
  return (c == 1);
}

int main() {
  ll n;
  cin >> n;
  vector<ll> v;
  v.push_back(n);
  v.push_back(n - 1);
  for (ll i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      v.push_back(i);
      v.push_back(n / i);
    }
  }
  for (ll i = 2; i * i <= n - 1; i++) {
    if ((n - 1) % i == 0) {
      v.push_back(i);
      v.push_back((n - 1) / i);
    }
  }
  set<int> s;
  for (auto x : v) {
    if (check(n, x))
      s.insert(x);
  }
  cout << s.size() << endl;
  return 0;
}
Problem p02722 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = int(a); i < (int)b; ++i)

using namespace std;
using ll = long long;

int main(void) {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  ll n, sqn, ans = 0;
  cin >> n;
  for (ll i = 1; i * i <= n; ++i)
    sqn = i;
  for (ll i = 2; i <= sqn; ++i) {
    if (n % i != 0)
      continue;
    ll t = n;
    while (t % i == 0) {
      t /= i;
    }
    if (t % i == 1)
      ++ans;
  }
  vector<ll> a;
  for (ll i = 1; i * i <= n - 1; ++i) {
    if ((n - 1) % i == 0) {
      a.push_back(i);
      if (i * i != n - 1)
        a.push_back((n - 1) / i);
    }
  }
  ans += a.size();
  cout << ans << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = int(a); i < (int)b; ++i)

using namespace std;
using ll = long long;

int main(void) {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  ll n, sqn, ans = 0;
  cin >> n;
  for (ll i = 1; i * i <= n; ++i)
    sqn = i;
  for (ll i = 2; i <= sqn; ++i) {
    if (n % i != 0)
      continue;
    ll t = n;
    while (t % i == 0) {
      t /= i;
    }
    if (t % i == 1)
      ++ans;
  }
  for (ll i = 2; i <= n; ++i) {
    if ((n - 1) % i == 0)
      ans++;
  }
  ans += 1;
  cout << ans << endl;

  return 0;
}
Problem p02722 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll N;
unordered_set<ll> v;
int f(ll k) {
  if (k < 2)
    return 0;
  if (!v.insert(k).second)
    return 0;
  ll n = N;
  while (n >= k) {
    if (n % k == 0)
      n /= k;
    else
      n %= k;
  }
  return n == 1 ? 1 : 0;
}
int main() {
  cin >> N;
  ll r = 0;
  for (ll n = N - 1; n <= N; ++n) {
    r += f(n);
    for (ll i = 2; i * i <= n; ++i)
      if (n % i == 0) {
        r += f(i);
        r += f(n / i);
      }
  }
  cout << r << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll N;
set<ll> v;
int f(ll k) {
  if (!v.insert(k).second)
    return 0;
  ll n = N;
  while (n >= k) {
    if (n % k == 0)
      n /= k;
    else
      n %= k;
  }
  return n == 1 ? 1 : 0;
}
int main() {
  cin >> N;
  ll r = 0;
  for (ll n = N - 1; n <= N; ++n) {
    r += f(n);
    for (ll i = 2; i * i <= n; ++i)
      if (n % i == 0) {
        r += f(i);
        r += f(n / i);
      }
  }
  cout << r << endl;
}
Problem p02722 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
ll n;
ll f(ll i) {
  ll now = n;
  while (now >= i) {
    if (now % i == 0)
      now /= i;
    else
      now %= i;
  }
  return now;
}

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

  cin >> n;

  if (n == 2) {
    cout << 1 << '\\n';
    return 0;
  }

  set<ll> x;

  for (ll i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      x.insert(i);
      x.insert(n / i);
    }
  }
  x.insert(n);

  n--;
  set<ll> y;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      y.insert(i);
      y.insert(n / i);
    }
  }
  y.insert(n);

  n++;
  set<ll> s;
  for (auto i = x.begin(); i != x.end(); i++) {
    if (f(*i) == 1)
      s.insert(*i);
  }

  cout << s.size() + y.size() << '\\n';
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
ll n;
ll f(ll i) {
  ll now = n;
  while (now >= i) {
    if (now % i == 0)
      now /= i;
    else
      now -= now / i * i;
  }
  return now;
}

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

  cin >> n;

  set<ll> x;

  for (ll i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      x.insert(i);
      x.insert(n / i);
    }
  }
  x.insert(n);

  n--;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      x.insert(i);
      x.insert(n / i);
    }
  }
  x.insert(n);

  n++;
  set<ll> s;
  for (auto i = x.begin(); i != x.end(); i++) {
    if (f(*i) == 1)
      s.insert(*i);
  }

  cout << s.size() << '\\n';
}
Problem p02722 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>
#define int long long
using namespace std;
const int INF = 1000000000000;
const int mod = 1000000007;
vector<int> res;
vector<int> ser;
void divisor(int n) {
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      res.push_back(i);
      if (i != n / i)
        res.push_back(n / i);
    }
  }
  if (n != 1) {
    res.push_back(n);
  }
}
void asd(int n) {
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      ser.push_back(i);
      if (i != n / i)
        ser.push_back(n / i);
    }
  }
  if (n != 1) {
    ser.push_back(n);
  }
}
signed main() {
  int n, ans = 0;
  cin >> n;
  divisor(n);
  asd(n - 1);
  for (int h = 0; h < res.size(); h++) {
    int a = n;
    while (a % res[h] == 0) {
      a /= res[h];
    }
    if ((a - 1) % res[h] == 0) {
      ans++;
    }
  }
  for (int h = 0; h < ser.size(); h++) {
    ans++;
  }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>
#define int long long
using namespace std;
const int INF = 1000000000000;
const int mod = 1000000007;
vector<int> divisor(int n) {
  vector<int> res;
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      res.push_back(i);
      if (i != n / i)
        res.push_back(n / i);
    }
  }
  if (n != 1) {
    res.push_back(n);
  }
  return res;
}
signed main() {
  int n, ans = 0;
  cin >> n;
  for (int h = 0; h < divisor(n).size(); h++) {
    int a = n;
    while (a % divisor(n)[h] == 0) {
      a /= divisor(n)[h];
    }
    if ((a - 1) % divisor(n)[h] == 0) {
      ans++;
    }
  }
  for (int h = 0; h < divisor(n - 1).size(); h++) {
    ans++;
  }
  cout << ans << endl;
  return 0;
}
Problem p02722 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(), a.end()
#define rrng(a) a.end(), a.begin()
#define endl "\\n"

ll N;

bool f(ll x) {
  ll n = N;
  if (x == 1)
    return false;
  while (n % x == 0)
    n /= x;
  return (n % x == 1);
}

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

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

  cin >> N;
  auto X = divisor(N);
  auto Y = divisor(N - 1);
  ll ans = 0;
  for (auto it : X) {
    ans += f(it);
  }
  for (auto it : Y) {
    ans += f(it);
  }
  cout << ans << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(), a.end()
#define rrng(a) a.end(), a.begin()
#define endl "\\n"

map<int_fast64_t, int> prime_factor(int_fast64_t x) {
  map<int_fast64_t, int> res;
  for (int_fast64_t i = 2; i * i <= x; i++) {
    while (x % i == 0) {
      res[i]++;
      x /= i;
    }
  }
  if (x != 1)
    res[x] = 1;
  return res;
}

vector<bool> eratosthenes(int n) {
  vector<bool> res(n + 1, true);
  res[0] = res[1] = false;
  for (int i = 2; i <= n; i++) {
    if (res[i])
      for (int j = i + i; j <= n; j += i) {
        res[j] = false;
      }
  }
  return res;
}

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

  ll N;
  cin >> N;
  auto X = prime_factor(N);
  vector<int> prime;
  vector<bool> isPrime = eratosthenes(N);
  for (int i = 0; i < isPrime.size(); i++)
    if (isPrime[i])
      prime.push_back(i);
  ll ans = 1;
  for (auto p : prime) {
    int res = 0;
    for (auto it : X) {
      ll n = N / (it.first * it.second);
      if (n % p == 1)
        res++;
    }
    if (res > 0)
      ans *= res + 1;
  }
  cout << ans + 1 << endl;

  return 0;
}