alexjercan/bugnet huggingface dataset:
Problem p02722 (C++) — buggy submission, verdict: Time Limit Exceeded

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

long long n, cnt;

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

  cin >> n;

  // no division
  // n % k = 1
  // n = 1 (mod k)
  // n - 1 = 0 (mod k)  we don't modify k
  // so we need to find factors of n - 1
  cnt = 0;
  for (long long i = 2; i * i <= n - 1; i++)
    if ((n - 1) % i == 0) {
      cnt += 2;
      if ((n - 1) / i == i)
        cnt--;
    }
  if (n - 1 > 1)
    cnt++;
  // div
  // if (x / k) mod k = 1 -> no more div
  for (long long i = 2; i * i <= n; i++)
    if (n % i == 0) {
      long long tmp = n;
      while (tmp % i == 0 && tmp >= i) {
        if (tmp % i == 0)
          tmp /= i;
        else
          tmp -= i;
      }
      // cout << i <<" " << tmp <<"\\n";
      if (tmp % i == 1 || tmp == 1)
        cnt++;
    }
  cnt++;

  cout << cnt << "\\n";
  return 0;
}
// (n, n - 1,
// 2 [2]
// 3 [2, 3]
// 4 [2, 3, 4]
// 5 [2, 4, 5]
// 6 [2, 5, 6]
// 7 [2, 3, 6, 7]
// 8 [2, 7, 8]
// 9 [2, 3, 4, 8, 9]
// 10[2, 3, 9 10]


Error: TLE

Fixed submission:

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

long long n, cnt;

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

  cin >> n;

  // no division
  // n % k = 1
  // n = 1 (mod k)
  // n - 1 = 0 (mod k)  we don't modify k
  // so we need to find factors of n - 1
  cnt = 0;
  for (long long i = 2; i * i <= n - 1; i++)
    if ((n - 1) % i == 0) {
      cnt += 2;
      if ((n - 1) / i == i)
        cnt--;
    }
  if (n - 1 > 1)
    cnt++;
  // div
  // if (x / k) mod k = 1 -> no more div
  for (long long i = 2; i * i <= n; i++)
    if (n % i == 0) {
      long long tmp = n;
      while (tmp % i != 1 && tmp >= i) {
        if (tmp % i == 0)
          tmp /= i;
        else
          tmp -= i;
      }
      // cout << i <<" " << tmp <<"\\n";
      if (tmp % i == 1 || tmp == 1)
        cnt++;
    }
  cnt++;

  cout << cnt << "\\n";
  return 0;
}
Problem p02722 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define IOS                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL)
#define pb push_back
#define ff first
#define ss second
#define rep(i, a, n) for (int i = a; i < n; i++)
#define M 1000000007
ll power(ll x, ll y, ll p) {
  int res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
int main() {
  ll n;
  cin >> n;
  if (n == 2) {
    cout << 1;
    return 0;
  }
  ll ans = 2;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i == 1) {
      if (n / i != i)
        ans += 2;
      else
        ans++;
    } else if (n % i == 0) {
      ll x = n;
      while (x >= i && x != 1) {
        if (x % i == 0)
          x /= i;
        else {
          ll y = x / i;
          y = y * i;
          x -= y;
          if (x != 1)
            break;
        }
      }
      if (x == 1)
        ans++;
    }
  }
  cout << ans;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define IOS                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL)
#define pb push_back
#define ff first
#define ss second
#define rep(i, a, n) for (int i = a; i < n; i++)
#define M 1000000007
ll power(ll x, ll y, ll p) {
  int res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
int main() {
  ll n;
  cin >> n;
  if (n == 2) {
    cout << 1;
    return 0;
  }
  ll ans = 2;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i == 1) {
      if (n / i != i)
        ans += 2;
      else
        ans++;
    } else if (n % i == 0) {
      ll x = n;
      while (x >= i && x != 1) {
        if (x % i == 0)
          x /= i;
        else {
          if (x % i == 1) {
            x = 1;
            break;
          }
        }
      }
      if (x == 1)
        ans++;
    }
  }
  cout << ans;
}
Problem p02722 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {

  int64_t N;
  cin >> N;
  int64_t ans = 0;

  int64_t M = N - 1;
  for (int64_t K = 2; K * K <= M; K++) {
    if (M % K == 0) {
      if (K * K != M)
        ans += 2;
      else
        ans++;
    }
  }
  if (M != 1) {
    ans++;
  }

  vector<int64_t> N_yakusuu;
  for (int64_t K = 2; K * K <= N; K++) {
    if (N % K == 0) {
      if (K * K != N) {
        N_yakusuu.push_back(K);
        N_yakusuu.push_back(N / K);
      } else {
        N_yakusuu.push_back(K);
      }
    }
  }
  N_yakusuu.push_back(N);

  int64_t n = N;
  for (int64_t K : N_yakusuu) {
    while (n % K == 0) {
      n = n / K;
    }
    if (n % K == 1) {
      ans++;
    }
    n = N;
  }

  cout << ans << endl;
}

Error: TLE

Fixed submission:

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

int main() {

  int64_t N;
  cin >> N;
  int64_t ans = 0;

  int64_t M = N - 1;
  for (int64_t K = 2; K * K <= M; K++) {
    if (M % K == 0) {
      if (K * K != M)
        ans += 2;
      else
        ans++;
    }
  }
  ans++;

  vector<int64_t> N_yakusuu;
  for (int64_t K = 1; K * K <= N; K++) {
    if (N % K == 0) {
      if (K * K != M) {
        N_yakusuu.push_back(K);
        N_yakusuu.push_back(N / K);
      } else {
        N_yakusuu.push_back(K);
      }
    }
  }
  N_yakusuu.push_back(N);

  int64_t n = N;
  for (int64_t K : N_yakusuu) {
    while (n % K == 0) {
      n = n / K;
    }
    if (n % K == 1) {
      ans++;
    }
    n = N;
  }

  cout << ans << endl;
}
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 < (n); i++)
typedef long long ll;

set<ll> factor(ll N) {
  ll max_a = (ll)sqrt(N);
  set<ll> factor_st;
  rep(i, max_a) {
    if (N % (i + 1) == 0) {
      factor_st.insert(i + 1);
      factor_st.insert(N / (i + 1));
    }
  }
  return factor_st;
}

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

  ll N;
  cin >> N;
  ll ans = 0;

  ans += factor(N - 1).size() - 1;
  set<ll> st;
  st = factor(N);

  for (auto v : st) {
    if (v == 1)
      continue;
    ll n = N;
    while (n % v == 0) {
      n /= v;
    }
    if (n % v == 1) {
      ++ans;
    }
  }

  cout << ans << "\\n";

  return 0;
}

Error: TLE

Fixed submission:

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

set<ll> factor(ll N) {
  ll max_a = (ll)sqrt(N);
  set<ll> factor_st;
  rep(i, max_a) {
    if (N % (i + 2) == 0) {
      factor_st.insert(i + 2);
      factor_st.insert(N / (i + 2));
    }
  }
  factor_st.insert(N);
  return factor_st;
}

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

  ll N;
  cin >> N;
  ll ans = 0;

  if (N != 2) {
    ans += factor(N - 1).size();
  }
  set<ll> st;
  st = factor(N);

  for (auto v : st) {
    ll n = N;
    while (n % v == 0) {
      n /= v;
    }
    if (n % v == 1) {
      ++ans;
    }
  }

  cout << ans << "\\n";

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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i, n, k) for (int i = (n); i < (k); i++)
#define ALL(a) (a).begin(), (a).end()
ll ans = 0;
ll calc(ll n, ll k) {
  if (n % k == 0)
    return n / k;
  else
    return n - k;
}
vector<ll> divisor(ll n) {
  vector<ll> div;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      if (i != 1)
        div.push_back(i);
      if (i * i != n)
        div.push_back(n / i);
    }
  }
  return div;
}
void Main() {
  ll n;
  cin >> n;
  vector<ll> div1 = divisor(n);
  vector<ll> div2 = divisor(n - 1);
  for (auto i : div1) {
    ll n2 = n;
    while (n2 >= i) {
      n2 = calc(n2, i);
      if (n2 % i == 1) {
        ans++;
        break;
      }
      if (n2 % i > 1) {
        break;
      }
    }
  }
  ans += div2.size();
  cout << ans << endl;
}
int main() {
  Main();
  /*
  東方風神録は神が出てくるので当然神ゲー
  */
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i, n, k) for (int i = (n); i < (k); i++)
#define ALL(a) (a).begin(), (a).end()
ll ans = 0;
ll calc(ll n, ll k) {
  if (n % k == 0)
    return n / k;
  else
    return n - k;
}
vector<ll> divisor(ll n) {
  vector<ll> div;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      if (i != 1)
        div.push_back(i);
      if (i * i != n)
        div.push_back(n / i);
    }
  }
  return div;
}
void Main() {
  ll n;
  cin >> n;
  vector<ll> div1 = divisor(n);
  vector<ll> div2 = divisor(n - 1);
  for (auto i : div1) {
    ll n2 = n;
    while (n2 >= i) {
      n2 = calc(n2, i);
      if (n2 % i == 1) {
        ans++;
        break;
      }
    }
  }
  ans += div2.size();
  cout << ans << endl;
}
int main() {
  Main();
  /*
  東方風神録は神が出てくるので当然神ゲー
  */
  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 < n; i++)
#define REP(i, s, n) for (int i = s; i < n; i++)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<double> vd;
typedef vector<vd> vvd;
const ll inf = pow(2, 31) - 1;
int main() {
  ll n;
  cin >> n;
  set<ll> f, g;
  ll cnt = 0;
  if (n == 2) {
    cout << 1 << endl;
    return 0;
  }
  REP(i, 1, (ll)sqrt(n) + 1) {
    if ((n - 1) % i == 0) {
      if (i == 1)
        f.insert(n - 1);
      else {
        f.insert((n - 1) / i);
        f.insert(i);
      }
    }
    if (n % i == 0) {
      g.insert(i);
      // cout << i << " ";
    }
  }
  // cout << endl;
  // cout << sqrt(n) + 1 << endl;

  for (auto it = g.begin(); it != g.end(); it++) {
    ll tmp1 = n, tmp2 = n, p = *it, q = n / p;
    if (p > 1) {
      while (tmp1 % p == 0)
        tmp1 /= p;
      if (tmp1 % p == 1)
        cnt++;
    }
    if (p != q) {
      while (tmp2 % q == 0)
        tmp2 /= q;
      if (tmp2 % q == 1)
        cnt++;
    }
    // cout << *it << " ";
  }
  // cout << endl;

  // cout << cnt << " " << f.size() << endl;
  cout << cnt + f.size() << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, s, n) for (int i = s; i < n; i++)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<double> vd;
typedef vector<vd> vvd;
const ll inf = pow(2, 31) - 1;
int main() {
  ll n;
  cin >> n;
  set<ll> f;
  REP(i, 1, sqrt(n) + 1) {
    if ((n - 1) % i == 0) {
      if (i == 1)
        f.insert(n - 1);
      else {
        f.insert((n - 1) / i);
        f.insert(i);
      }
    }
    if (n % i == 0) {
      ll tmp = n, tmq = n;
      ll j = n / i;
      if (i > 1) {
        while (tmp % i == 0)
          tmp /= i;
        if (tmp % i == 1)
          f.insert(i);
      }
      while (tmq % j == 0)
        tmq /= j;
      if (tmq % j == 1)
        f.insert(j);
    }
  }
  cout << f.size() << endl;

  // for(auto it=f.begin();it!=f.end();it++)cout << *it << " ";
  // cout << endl;
  return 0;
}
Problem p02722 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template <typename T> vector<T> make_v(size_t a, T b) {
  return vector<T>(a, b);
}

template <typename... Ts> auto make_v(size_t a, Ts... ts) {
  return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

set<ll> div(ll x) {
  set<ll> r;

  for (ll d = 1; d * d <= x; d++) {
    if (x % d == 0) {
      r.insert(d);
      r.insert(x / d);
    }
  }

  return r;
}

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

  auto s1 = div(n), s2 = div(n - 1);

  s1.insert(s2.begin(), s2.end());

  int ans = 0;
  for (ll k : s1) {
    if (k == 1)
      continue;

    ll x = n;
    while (x >= k) {
      if (x % k == 0) {
        x /= k;
      } else {
        x %= k;
      }
    }

    if (x == 1)
      ans++;
  }

  cout << ans << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template <typename T> vector<T> make_v(size_t a, T b) {
  return vector<T>(a, b);
}

template <typename... Ts> auto make_v(size_t a, Ts... ts) {
  return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

map<ll, int> fact(ll x) {
  map<ll, int> r;

  ll n = x;
  for (ll d = 2; d * d <= n; d++) {
    while (n % d == 0) {
      r[d]++;
      n /= d;
    }
  }

  if (n > 1)
    r[n]++;

  return r;
}

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

  vector<ll> s;
  for (auto itr : fact(n)) {
    REP(_, itr.second) s.push_back(itr.first);
  }

  int t = 1;
  for (auto itr : fact(n - 1)) {
    t *= itr.second + 1;
  }

  int c = 0;
  set<ll> st;
  REP(b, bit(s.size())) {
    ll k = 1;
    REP(i, s.size()) {
      if (b & bit(i))
        k *= s[i];
    }

    if (k == 1 || st.find(k) != st.end())
      continue;
    st.insert(k);

    ll x = n;
    while (x >= k) {
      if (x % k == 0) {
        x /= k;
      } else {
        x %= k;
      }
    }

    if (x == 1)
      c++;
  }

  cout << (t - 1) + c << endl;

  return 0;
}
Problem p02722 (C++) — buggy submission, verdict: Runtime Error

#include <cmath>
#include <iostream>

using namespace std;

int main() {
  long long n;
  cin >> n;
  if (n == 2) {
    cout << "1\\n";
    return 0;
  }
  double level = sqrt(n);
  long long count = 2;
  long long work;
  long long j;
  for (long long i = 2; i <= level; i++) {
    if (n % i == 0) {
      work = n;
      while (work >= i) {
        if (work % i == 0)
          work /= i;
        else
          work %= i;
      }
      if (work == 1)
        count++;
      if ((double)i != level) {
        work = n;
        j = n / i;
        while (work >= j) {
          if (work % j == 0)
            work /= j;
          else
            work %= j;
        }
        if (work == 1)
          count++;
      }
    }
    if ((n - 1) % i == 0) {
      if ((double)i == sqrt(n - 1))
        count++;
      else
        count += 2;
    }
  }
  cout << count << "\\n";
}


Error: 0

Fixed submission:

#include <cmath>
#include <iostream>

using namespace std;

int main() {
  long long n;
  cin >> n;
  if (n == 2) {
    cout << "1\\n";
    return 1;
  }
  double level = sqrt(n);
  long long count = 2;
  long long work;
  long long j;
  for (long long i = 2; i <= level; i++) {
    if (n % i == 0) {
      work = n;
      while (work >= i) {
        if (work % i == 0)
          work /= i;
        else
          work %= i;
      }
      if (work == 1)
        count++;
      if ((double)i != level) {
        work = n;
        j = n / i;
        while (work >= j) {
          if (work % j == 0)
            work /= j;
          else
            work %= j;
        }
        if (work == 1)
          count++;
      }
    }
    if ((n - 1) % i == 0) {
      if ((double)i == sqrt(n - 1))
        count++;
      else
        count += 2;
    }
  }
  cout << count << "\\n";
}
Problem p02722 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef pair<int, int> pii;
typedef pair<int, pii> p;
typedef long long ll;
typedef pair<ll, ll> pll;
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
const int MAXN = 100000;
const int MAXE = 100000;
const int MAXV = 10000;
const ll INF = 2e9;
const ll MOD = 1e9 + 7;
struct edge {
  int to;
  int cost;
};
vector<ll> diviser(ll X) {
  vector<ll> res;
  for (ll i = 1; i * i <= X; ++i) {
    if (X % i == 0) {
      res.push_back(i);
      if (i != X / i)
        res.push_back(X / i);
    }
  }
  sort(res.begin(), res.end());
  return res;
}
int main() {
  ll N;
  cin >> N;
  auto res1 = diviser(N - 1);
  auto res2 = diviser(N);
  ll ans = (int)res1.size() - 1;
  for (auto it : res2) {
    if (it == 1)
      continue;
    ll M = N;
    while (M % it == 0)
      M /= it;
    if (M % it == 1)
      ans++;
  }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef pair<int, int> pii;
typedef pair<int, pii> p;
typedef long long ll;
typedef pair<ll, ll> pll;
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
const int MAXN = 100000;
const int MAXE = 100000;
const int MAXV = 10000;
const ll INF = 2e9;
const ll MOD = 1e9 + 7;
struct edge {
  int to;
  int cost;
};
vector<ll> diviser(ll X) {
  vector<ll> res;
  for (int i = 1; i * i <= X; ++i) {
    if (X % i == 0) {
      res.push_back(i);
      if (i != X / i)
        res.push_back(X / i);
    }
  }
  sort(res.begin(), res.end());
  return res;
}
int main() {
  ll N;
  cin >> N;
  auto res1 = diviser(N - 1);
  auto res2 = diviser(N);
  ll ans = (int)res1.size() - 1;
  for (auto it : res2) {
    if (it == 1)
      continue;
    ll M = N;
    while (M % it == 0)
      M /= it;
    if (M % it == 1)
      ans++;
  }
  cout << ans << endl;
  return 0;
}
Problem p02722 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <vector>

#define reps(i, s, n) for (int(i) = (s); (i) < (n); (i)++)
#define rep(i, n) reps(i, 0, n)
using namespace std;
using ll = long long;

map<int64_t, int64_t> prime_factor(int64_t n) {
  map<int64_t, int64_t> ret;
  for (int64_t i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if (n != 1)
    ret[n] = 1;
  return ret;
}

int main() {
  ll n;
  cin >> n;
  auto pf = prime_factor(n - 1);
  vector<ll> vec;
  ll ans = 1;

  for (auto e : pf) {
    ans *= (e.second + 1);
  }
  ans--;

  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      // cout << i << " " << n/i << endl;
      vec.push_back(i);
      if (i != 1 && i * i != n)
        vec.push_back(n / i);
    }
  }

  for (auto e : vec) {
    // cout <<e << endl;
    if (e == 1)
      continue;
    ll tmp = n;
    while (tmp % e == 0) {
      tmp /= e;
    }
    if (tmp % e == 1) {
      ans++;
    }
  }

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


Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <vector>

#define reps(i, s, n) for (int(i) = (s); (i) < (n); (i)++)
#define rep(i, n) reps(i, 0, n)
using namespace std;
using ll = long long;

map<int64_t, int64_t> prime_factor(int64_t n) {
  map<int64_t, int64_t> ret;
  for (int64_t i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if (n != 1)
    ret[n] = 1;
  return ret;
}

int main() {
  ll n;
  cin >> n;
  auto pf = prime_factor(n - 1);
  vector<ll> vec;
  ll ans = 1;

  for (auto e : pf) {
    ans *= (e.second + 1);
  }
  ans--;

  for (int i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      if (i != 1)
        vec.push_back(i);
      if (i != 1 && i * i != n)
        vec.push_back(n / i);
    }
  }

  for (auto e : vec) {
    ll tmp = n;
    while (tmp % e == 0) {
      tmp /= e;
    }
    if (tmp % e == 1) {
      ans++;
    }
  }

  cout << ans + 1 << endl;

  return 0;
}
Problem p02722 (C++) — buggy submission, verdict: Runtime Error

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

#define pb push_back
#define all(a) (a).begin(), (a).end()

using ll = long long;
using pii = pair<int, int>;

bool check(ll n, ll x) {
  while (n % x == 0)
    n /= x;
  return (n % x == 1);
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n;
  cin >> n;
  if (n == 2) {
    cout << 1;
    return 0;
  }
  set<ll> ans;
  ll t = n - 1;
  ans.insert(n - 1);
  for (ll i = 2; i * i <= t; ++i) {
    if (t % i == 0) {
      ans.insert(i);
      ans.insert(t / i);
    }
  }

  ans.insert(n);
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      if (check(n, i))
        ans.insert(i);
      if (check(n, n / i))
        ans.insert(n / i);
    }
  }
  assert(!ans.count(1));
  cout << ans.size() << '\\n';
}

Error: 0

Fixed submission:

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

#define pb push_back
#define all(a) (a).begin(), (a).end()

using ll = long long;
using pii = pair<int, int>;

bool check(ll n, ll x) {
  while (n % x == 0)
    n /= x;
  return (n % x == 1);
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n;
  cin >> n;
  set<ll> ans;
  ll t = n - 1;
  ans.insert(n - 1);
  for (ll i = 2; i * i <= t; ++i) {
    if (t % i == 0) {
      ans.insert(i);
      ans.insert(t / i);
    }
  }

  ans.insert(n);
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      if (check(n, i))
        ans.insert(i);
      if (check(n, n / i))
        ans.insert(n / i);
    }
  }
  assert(!ans.count(1));
  cout << ans.size() << '\\n';
}
Problem p02722 (C++) — buggy submission, verdict: Runtime Error

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools

#include <bits/stdc++.h>

using namespace std;

using i64 = long long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;

template <typename T> bool chmin(T &x, T y) {
  if (x > y) {
    x = y;
    return true;
  }
  return false;
}

template <typename T> bool chmax(T &x, T y) {
  if (x < y) {
    x = y;
    return true;
  }
  return false;
}

auto divisor = [](i64 x) {
  int sq = sqrt(x) + 1;
  vector<i64> ret;
  for (i64 i = 1; i < sq; ++i)
    if (!(x % i)) {
      if (i != 1)
        ret.emplace_back(i);
      if (__int128_t(i) * i != x && x / i != 1)
        ret.emplace_back(x / i);
    }
  sort(ret.begin(), ret.end());
  return ret;
};

void solve(long long n) {

  i64 ans = 0;

  auto n_div = divisor(n);
  auto m_div = divisor(n - 1);

  ans += m_div.size();

  for (auto &k : n_div) {
    for (__int128 kp = k; kp <= n && n % kp == 0; kp *= k) {
      if ((n / kp) % k == 1) {
        ++ans;
        break;
      }
    }
  }

  cout << ans << endl;
}

signed main() {
  long long N;
  scanf("%lld", &N);
  solve(N);
  return 0;
}


Error: 0

Fixed submission:

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools

#include <bits/stdc++.h>

using namespace std;

using i64 = long long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;

template <typename T> bool chmin(T &x, T y) {
  if (x > y) {
    x = y;
    return true;
  }
  return false;
}

template <typename T> bool chmax(T &x, T y) {
  if (x < y) {
    x = y;
    return true;
  }
  return false;
}

auto divisor = [](i64 x) {
  int sq = sqrt(x) + 1;
  vector<i64> ret;
  for (i64 i = 1; i < sq; ++i)
    if (!(x % i)) {
      if (i != 1)
        ret.emplace_back(i);
      if (i * i != x && x / i != 1)
        ret.emplace_back(x / i);
    }
  sort(ret.begin(), ret.end());
  return ret;
};

void solve(long long n) {

  i64 ans = 0;

  auto n_div = divisor(n);
  auto m_div = divisor(n - 1);

  ans += m_div.size();

  for (auto &k : n_div) {
    for (i64 kp = k; kp <= n; kp *= k) {
      if ((n / kp) % k == 1) {
        ++ans;
        break;
      }
    }
  }

  cout << ans << endl;
}

signed main() {
  long long N;
  scanf("%lld", &N);
  solve(N);
  return 0;
}