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

#include <bits/stdc++.h>
using namespace std;
queue<long long> m;
void yaku(long long n) {
  if (n != 1)
    m.push(n);
  for (long long i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      m.push(i);
      if (i * i != n)
        m.push(n / i);
    }
  }
  return;
}
int main() {
  long long n;
  cin >> n;
  yaku(n);
  long long ans = 0;
  while (!m.empty()) {
    long long tmp = m.front();
    long long nn = n;
    while (nn % tmp == 0) {
      nn /= tmp;
    }
    if (nn % tmp == 1)
      ans++;
    m.pop();
  }
  yaku(n - 1);
  while (!m.empty()) {
    ans++;
    m.pop();
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
vector<long long> a(1000001, 0ll);
vector<long long> b;
void pr(long long n) {
  for (long long i = 2; i * i <= n; i++) {
    long long count = 0;
    while (n % i == 0) {
      count++;
      n /= i;
    }
    a.at(i) = count;
  }
  return;
}
void prv(long long n) {
  for (long long i = 2; i * i <= n; i++) {
    long long count = 0;
    while (n % i == 0) {
      count++;
      n /= i;
    }
    b.push_back(count);
  }
  if (n != 1)
    b.push_back(1);
  return;
}
long long pow(long long n, long long m) {
  long long ans = 1;
  while (m > 0) {
    if (m & 1)
      ans *= n;
    n = n * n;
    m >> 1;
  }
  return ans;
}
int main() {
  long long n;
  cin >> n;
  pr(n);
  long long ans = 1;
  for (long long i = 2; i * i <= n; i++) {
    for (long long j = 1; j <= a.at(i); j++) {
      long long tmp = n;
      long long d = pow(i, j);
      while (tmp % d == 0) {
        tmp /= d;
      }
      if (tmp % d == 1) {
        ans++;
      }
    }
  }
  prv(n - 1);
  long long q = 1;
  for (long long i = 0; i < b.size(); i++) {
    q *= (b.at(i) + 1);
  }
  ans = ans + q - 1;
  cout << ans << endl;
}
Problem p02722 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define N 400050
#define int long long
#define pb push_back
#define x first
#define y second
#define all(v) v.begin(), v.end()
#define coffee prince
#define sz(a) (int)a.size()
#define ll long long
#define SIZE N
using namespace std;
ll n, ans;
set<ll> pr;
bool che(int x) {
  if (x < 2 || x > n)
    return 0;
  ll m = n;
  while ((m % x) == 0) {
    m /= x;
  }
  m %= x;
  if (m == 1)
    return 1;
  return 0;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  ll val = n - 1;
  for (ll i = 2; i * i <= val; i++) {
    if (val % i)
      continue;
    pr.insert(i);
    pr.insert(val / i);
  }
  pr.insert(n);
  pr.insert(n - 1);
  for (ll i = 2; i * i <= n; i++) {
    if (n % i)
      continue;
    pr.insert(i);
    ll j = n / i;
    pr.insert(j);
  }
  for (auto ch : pr)
    if (che(ch))
      ans++;
  cout << ans;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define N 400050
#define int long long
#define pb push_back
#define x first
#define y second
#define all(v) v.begin(), v.end()
#define coffee prince
#define sz(a) (int)a.size()
#define ll long long
#define SIZE N
using namespace std;
ll n, ans;
set<ll> pr;
ll che(ll x) {
  ll m = n;
  while ((m % x) == 0) {
    m /= x;
  }
  m %= x;
  if (m == 1)
    return 1;
  return 0;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  ll val = n - 1;
  for (ll i = 2; i * i <= val; i++) {
    if (val % i)
      continue;
    pr.insert(i);
    pr.insert(val / i);
  }
  pr.insert(n);
  pr.insert(n - 1);
  for (ll i = 2; i * i <= n; i++) {
    if (n % i)
      continue;
    pr.insert(i);
    ll j = n / i;
    pr.insert(j);
  }
  for (auto ch : pr)
    if (che(ch))
      ans++;
  cout << ans;
  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, n) for (int i = 1; i <= n; i++)
typedef long long ll;

vector<pair<ll, ll>> factorize(ll n) {
  vector<pair<ll, ll>> res;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i)
      continue;
    res.emplace_back(i, 0);
    while (n % i == 0) {
      n /= i;
      res.back().second++;
    }
  }
  if (n != 1)
    res.emplace_back(n, 1);
  return res;
}

int main() {
  ll n;
  cin >> n;
  ll ans = 0;
  for (ll i = 2; i * i <= n; ++i) {
    ll temp = n;
    if (temp % i)
      continue;
    while (temp % i == 0) {
      temp /= i;
    }
    if (temp % i == 1)
      ans++;
  }
  auto v = factorize(n - 1);
  ll yakusuu = 1;
  rep(i, v.size()) { yakusuu *= v[i].second + 1; }
  yakusuu--;
  ans += yakusuu + 1;
  cout << ans << 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, n) for (int i = 1; i <= n; i++)
typedef long long ll;

vector<pair<ll, ll>> factorize(ll n) {
  vector<pair<ll, ll>> res;
  for (int i = 2; i * i <= n; ++i) {
    if (n % i)
      continue;
    res.emplace_back(i, 0);
    while (n % i == 0) {
      n /= i;
      res.back().second++;
    }
  }
  if (n != 1)
    res.emplace_back(n, 1);
  return res;
}

int main() {
  ll n;
  cin >> n;
  ll ans = 0;
  for (ll i = 2; i * i <= n; ++i) {
    ll temp = n;
    if (temp % i)
      continue;
    while (temp % i == 0) {
      temp /= i;
    }
    if (temp % i == 1)
      ans++;
  }
  auto v = factorize(n - 1);
  ll yakusuu = 1;
  rep(i, v.size()) { yakusuu *= v[i].second + 1; }
  yakusuu--;
  ans += yakusuu + 1;
  cout << ans << endl;
  return 0;
}
Problem p02722 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
ll mod = 1000000007;

int main() {
source:
  ll n;
  cin >> n;
  set<ll> m;
  ll sq = sqrt(n);

  repd(i, 2, sq + 1) {
    if (n % i == 0) {
      m.insert(i);
      m.insert(n / i);
    }
    if ((n - 1) % i == 0) {
      m.insert(i);
      m.insert((n - 1) / i);
    }
  }

  m.insert(n - 1);
  m.insert(n);
  ll ans = 0;
  for (auto iter = m.begin(); iter != m.end(); iter++) {
    ll num = *iter;
    if (num == 1) {
      continue;
    }
    ll temp = n;
    while (temp > 0) {
      if (temp % num == 0) {
        temp /= num;
      } else {
        temp %= num;
      }

      if (temp == 1) {
        ans++;
        break;
      } else if (temp < num) {
        if (temp < num) {
          break;
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
ll mod = 1000000007;

int main() {
source:
  ll n;
  cin >> n;
  set<ll> m;
  ll sq = sqrt(n);

  repd(i, 2, sq + 1) {
    if (n % i == 0) {
      m.insert(i);
      m.insert(n / i);
    }
    if ((n - 1) % i == 0) {
      m.insert(i);
      m.insert((n - 1) / i);
    }
  }

  m.insert(n - 1);
  m.insert(n);
  ll ans = 0;
  for (auto num : m) {
    ll temp = n;
    while (temp > 0) {
      if (temp % num == 0) {
        temp /= num;
      } else {
        temp %= num;
      }

      if (temp == 1) {
        ans++;
        break;
      } else if (temp < num) {
        if (temp < num) {
          break;
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02722 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define lli long long int
#define REP(i, s, n) for (int i = s; i < n; i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL << 50)
#define DEBUG 0
#define mp(a, b) make_pair(a, b)
#define SORT(V) sort(V.begin(), V.end())
#define PI (3.141592653589794)

set<lli> yaku(lli num) {
  set<lli> rtn;
  for (lli i = 1; i * i <= num; i++) {
    if (num % i == 0) {
      rtn.insert(i);
      rtn.insert(num / i);
    }
  }
  return rtn;
}
bool ok(lli n, lli k) {
  if (n == 1)
    return true;
  if (n < k)
    return false;
  if (n % k == 0)
    return ok(n / k, k);
  else
    return ok(n % k, k);
}

void func(long long N) {
  set<lli> y = yaku(N);
  set<lli> yy = yaku(N - 1);

  lli cnt = 0;

  for (auto e : y) {
    if (e == 1)
      continue;
    if (ok(N, e))
      cnt++;
  }
  for (auto e : yy) {
    if (y.find(e) != y.end())
      continue;
    if (ok(N, e))
      cnt++;
  }
  cout << cnt << endl;
}

int main() {
  // cout << fixed << setprecision(5);

  long long N;
  scanf("%lld", &N);
  func(N);
  return 0;
}


Error: TLE

Fixed submission:

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

#define lli long long int
#define REP(i, s, n) for (int i = s; i < n; i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL << 50)
#define DEBUG 0
#define mp(a, b) make_pair(a, b)
#define SORT(V) sort(V.begin(), V.end())
#define PI (3.141592653589794)

set<lli> yaku(lli num) {
  set<lli> rtn;
  for (lli i = 1; i * i <= num; i++) {
    rtn.insert(i);
    rtn.insert(num / i);
  }
  return rtn;
}
bool ok(lli n, lli k) {
  if (n == 1)
    return true;
  if (n < k)
    return false;
  if (n % k == 0)
    return ok(n / k, k);
  else
    return ok(n % k, k);
}

void func(long long N) {
  set<lli> y = yaku(N);
  set<lli> yy = yaku(N - 1);

  lli cnt = 0;

  for (auto e : y) {
    if (e == 1)
      continue;
    if (ok(N, e))
      cnt++;
  }
  for (auto e : yy) {
    if (y.find(e) != y.end())
      continue;
    if (ok(N, e))
      cnt++;
  }
  cout << cnt << endl;
}

int main() {
  // cout << fixed << setprecision(5);

  long long N;
  scanf("%lld", &N);
  func(N);
  return 0;
}
Problem p02722 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
  int n;
  cin >> n;
  int ans = 0;
  // 因为k>=2,所以从2开始枚举
  for (int i = 2; i * i <= n - 1; i++) { // 找n-1的约数
    if ((n - 1) % i == 0) {
      ans++;
      if ((n - 1) / i != i)
        ans++;
    }
  }
  if (n - 1 >= 2)
    ans++;                           // n-1本身也算
  for (int i = 2; i * i <= n; i++) { // 找n的约数
    if (n % i == 0) {
      int t = n;
      while (t % i == 0)
        t /= i;
      if (t % i == 1)
        ans++;
      if (n / i != i) {
        int t = n, tt = n / i;
        while (t % tt == 0)
          t /= tt;
        if (t % tt == 1)
          ans++;
      }
    }
  }
  if (n >= 2)
    ans++; // n除以n等于1
  cout << ans << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

signed main() {
  int n;
  cin >> n;
  int ans = 0;
  // 因为k>=2,所以从2开始枚举
  for (int i = 2; i * i <= n - 1; i++) { // 找n-1的约数
    if ((n - 1) % i == 0) {
      ans++;
      if ((n - i) / i != i)
        ans++;
    }
  }
  if (n - 1 >= 2)
    ans++;                           // n-1本身也算
  for (int i = 2; i * i <= n; i++) { // 找n的约数
    if (n % i == 0) {
      int t = n;
      while (t % i == 0)
        t /= i;
      if (t % i == 1)
        ans++;
    }
  }
  if (n >= 2)
    ans++; // n除以n等于1
  cout << ans << endl;
  return 0;
}
Problem p02722 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstring>
#include <iostream>
#include <math.h>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string>

using namespace std;

typedef long long ll;
typedef double db;

ll mod = 1e9 + 7;

ll a[10000][2];

int main() {
  ll n;
  int count = 0;
  cin >> n;
  ll s = 0;
  if (n == 2)
    s--;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i == 1) {
      if ((n - 1) / i == i)
        s++;
      else
        s += 2;

    } else if (n % i == 0) {
      a[count][0] = i;
      a[count][1] = n / i;
      count++;
    }
  }
  for (int j = 0; j < count; j++) {
    while (a[j][1] >= a[j][0]) {
      if (a[j][1] % a[j][0] == 1) {
        s++;
        break;
      } else if (a[j][1] % a[j][0] == 0)
        a[j][1] = a[j][1] / a[j][0];
      else
        break;
    }
    if (a[j][1] == 1)
      s++;
  }
  cout << s + 2;
  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <cstring>
#include <iostream>
#include <math.h>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string>

using namespace std;

typedef long long ll;
typedef double db;

ll mod = 1e9 + 7;

ll a[500][2];

int main() {
  ll n;
  int count = 0;
  cin >> n;
  ll s = 0;
  if (n == 2)
    s--;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i == 1) {
      if ((n - 1) / i == i)
        s++;
      else
        s += 2;

    } else if (n % i == 0) {
      a[count][0] = i;
      a[count][1] = n / i;
      count++;
    }
  }
  for (int j = 0; j < count; j++) {
    while (a[j][1] >= a[j][0]) {
      if (a[j][1] % a[j][0] == 1) {
        s++;
        break;
      } else if (a[j][1] % a[j][0] == 0)
        a[j][1] = a[j][1] / a[j][0];
      else
        break;
    }
    if (a[j][1] == 1)
      s++;
  }
  cout << s + 2;
  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)

using namespace std;
using ll = long long;

int main() {
  ll n, ans = 0;
  cin >> n;
  vector<ll> num;
  rep(k, 2) {
    n -= (ll)k;
    if (n != 1)
      num.push_back(n);
    for (ll i = 2; i * i <= n; i++) {
      if (n % i == 0) {
        num.push_back(i);
        if (i * i != n)
          num.push_back(n / i);
      }
    }
    n += k;
  }
  for (ll i : num) {
    ll a = n;
    while (a % i == 0)
      a /= i;
    if (a % i == 1) {
      ans++;
    }
  }
  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)

using namespace std;
using ll = long long;

int main() {
  ll n, ans = 0;
  cin >> n;
  vector<ll> num;
  rep(k, 2) {
    n -= (ll)k;
    num.push_back(n);
    for (ll i = 2; i * i <= n; i++) {
      if (n % i == 0) {
        num.push_back(i);
        if (i * i != n)
          num.push_back(n / i);
      }
    }
    n += k;
  }
  for (ll i : num) {
    ll a = n;
    while (a % i == 0)
      a /= i;
    if (a % i == 1) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02722 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define dforsn(i, s, n) for (int i = int(n - 1); i >= int(s); i--)
#define forsn(i, s, n) for (int i = int(s); i < int(n); i++)
#define dforn(i, n) for (int i = int(n - 1); i >= 0; i--)
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define D(a) cerr << #a << " = " << a << endl
#define all(a) a.begin(), a.end()
#define si(a) int((a).size())
typedef pair<int, int> pii;
typedef long long int ll;
typedef vector<int> vi;
#define pb emplace_back
#define mp make_pair
#define snd second
#define fst first

typedef vector<ll> vll;

vll divisors(ll x) { // O(sqrt x)
  vll r;
  for (ll i = 1; i * i <= x; i++) {
    ll d = x / i;
    if (d * i == x) {
      if (i != 1)
        r.pb(i);
      if (d != i)
        r.pb(d);
    }
  }
  return r;
}

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

  ll n;
  cin >> n;
  int ans = si(divisors(n - 1));
  vll d = divisors(n);
  for (ll x : d) {
    ll y = n;
    while (y % x == 0)
      y /= x;
    if ((y - 1) % x == 0)
      ans++;
  }
  cout << ans << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

#define dforsn(i, s, n) for (int i = int(n - 1); i >= int(s); i--)
#define forsn(i, s, n) for (int i = int(s); i < int(n); i++)
#define dforn(i, n) for (int i = int(n - 1); i >= 0; i--)
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define D(a) cerr << #a << " = " << a << endl
#define all(a) a.begin(), a.end()
#define si(a) int((a).size())
typedef pair<int, int> pii;
typedef long long int ll;
typedef vector<int> vi;
#define pb emplace_back
#define mp make_pair
#define snd second
#define fst first

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

  ll n;
  cin >> n;
  set<ll> s;
  for (ll x = 1; x * x <= n; x++) {
    if (n % x == 0) {
      ll y = n / x;
      ll v = y;
      while (v % x == 0) {
        if ((v - 1) % x == 0)
          s.insert(x);
        v /= x;
      }
      v = x;
      while (v % y == 0) {
        if ((v - 1) % y == 0)
          s.insert(y);
        v /= y;
      }
    }
  }
  n--;
  for (ll x = 1; x * x <= n; x++) {
    if (n % x == 0) {
      ll y = n / x;
      if (x != 1)
        s.insert(x);
      if (y != x)
        s.insert(y);
    }
  }

  cout << si(s) << endl;
  return 0;
}
Problem p02722 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int main() {
  long long n;
  cin >> n;
  long long cnt = 0;
  if (n == 2) {
    cout << 1 << endl;
    return 0;
  }
  for (long long i = 1; i * i <= n - 1; i++) {
    if (!((n - 1) % i)) {
      cnt += 2;
      if ((n - 1) / i == i)
        cnt--;
    }
  }
  cnt--;
  cnt++;
  for (long long i = 2; i * i <= n; i++) {
    if (n % i)
      continue;
    long long tn = n;
    long long a = n / i;
    while (!(tn % i))
      tn /= i;
    if (tn % i == 1)
      cnt++;
    if (a == i)
      continue;
    tn = n;
    while (!(tn % a))
      tn /= a;
    if (tn % a == 1)
      cnt++;
  }
  cout << cnt << endl;
  return 0;
}


Error: -8

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  long long n;
  cin >> n;
  int cnt = 0;
  if (n == 2) {
    cout << 1 << endl;
    return 0;
  }
  for (long long i = 1; i * i <= n - 1; i++) {
    if (i == 1) {
      cnt++;
      continue;
    }
    if (!((n - 1) % i))
      cnt += 2;
    if ((n - 1) / i == i)
      cnt--;
  }
  cnt++;
  for (long long i = 0; i * i <= n; i++) {
    if (n % i)
      continue;
    long long tn = n;
    long long a = n / i;
    while (!(tn % i))
      tn /= i;
    if (tn % i == 1)
      cnt++;
    if (a == i)
      continue;
    tn = n;
    while (!(tn % a))
      tn /= a;
    if (tn % a == 1)
      cnt++;
  }
  cout << cnt << endl;
  return 0;
}
Problem p02722 (C++) — buggy submission, verdict: Runtime Error

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

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

  vector<long long int> div1;
  for (long long int i = 1; i * i <= n - 1; i++) {
    if ((n - 1) % i == 0) {
      div1.push_back(i);

      long long int j = (n - 1) / i;
      if (j != i)
        div1.push_back(j);
    }
  }
  long long int ans = div1.size() - 1; // removed 1

  vector<long long int> div2;
  for (long long int i = 2; i * i <= n; i++) {
    if (n % i == 0)
      div2.push_back(i);
  }

  int m = div2.size();
  for (int i = 0; i < m; i++) {
    long long int a = n;
    while (a > 0) {
      if (a % div2[i] == 0)
        a /= div2[i];
      else
        break;
    }
    if (a % div2[i] == 1)
      ans += 1;
  }
  ans += 1; // self
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

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

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

  vector<long long int> div1;
  for (long long int i = 1; i * i <= n - 1; i++) {
    if ((n - 1) % i == 0) {
      div1.push_back(i);

      long long int j = (n - 1) / i;
      if (j != i)
        div1.push_back(j);
    }
  }
  long long int ans = div1.size() - 1; // removed 1

  vector<long long int> div2;
  for (long long int i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      div2.push_back(i);

      long long int j = n / i;
      if (j != i)
        div2.push_back(j);
    }
  }
  sort(div2.begin(), div2.end());

  long long int m = div2.size();
  for (long long int i = 0; i < m; i++) {
    long long int d = div2[i];
    bool flag = false;
    while (d < n) {
      if ((n - d) % (d * div2[i]) == 0) {
        flag = true;
        break;
      }
      d *= div2[i];
    }
    if (flag == true)
      ans += 1;
  }
  ans += 1; // self
  cout << ans << endl;
  return 0;
}
Problem p02722 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define LL long long
LL n, cnt;
int judge(LL k, LL m) {
  while (m >= k) {
    if (m % k == 0)
      m /= k;
    else
      m %= k;
  }
  if (m == 1)
    return 1;
  else
    return 0;
}
int main() {
  LL i;
  scanf("%lld", &n);
  if (n == 2) {
    printf("1\\n");
    return 0;
  }
  for (i = 2; i * i <= n - 1; i++)
    if ((n - 1) % i == 0) {
      cnt++;
      if (i != (n - 1) / i)
        cnt++;
    }
  cnt++;
  for (i = 2; i * i <= n; i++)
    if (n % i == 0) {
      if (judge(i, n))
        cnt++;
      if (i != n / i && judge(n / i, n))
        cnt++;
    }
  cnt++;
  printf("%lld\\n", cnt);
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  int cnt = 0;
  long long i, k, n;
  cin >> n;
  i = n;
  for (k = 2; k <= n; k++) {
    while (n % k == 0) {
      n /= k;
    }
    if (n % k == 1)
      cnt++;
    n = i;
  }
  cout << cnt;
  return 0;
}
Problem p02722 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
random_device rnd;
mt19937 mt(rnd());
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;
const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1000000007;
vector<ll> ans;

bool ok(ll n, ll k) {
  // assert(2 <= k && k <= n);
  while (n % k == 0 && k != 1)
    n /= k;
  // cerr << k << " " << n % k << endl;
  return n % k == 1ll;
}
int main() {
  ll n;
  cin >> n;
  int ans = 0;
  rep(p, 1, n + 1) {
    if (n < p * p)
      break;
    if (n % p == 0) {
      if (ok(n, p))
        ans++;
      if (p != n / p) {
        if (ok(n, n / p))
          ans++;
      }
    }
  }
  n--;
  rep(p, 1, n + 1) {
    if (n < p * p)
      break;
    if (n % p == 0) {
      if (ok(n + 1, p))
        ans++;
      if (p != n / p) {
        if (ok(n + 1, n / p))
          ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
random_device rnd;
mt19937 mt(rnd());
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;
const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1000000007;
vector<ll> ans;

bool ok(ll n, ll k) {
  assert(2 <= k && k <= n);
  while (n % k == 0)
    n /= k;
  return n % k == 1ll;
}

vector<ll> prime;
void initprime() {
  prime.push_back(2);
  rep(i, 3, 1010101) {
    bool isprime = true;
    rep(j, prime.size()) {
      if (prime[j] * prime[j] > i) {
        break;
      }
      if (i % prime[j] == 0) {
        isprime = false;
        break;
      }
    }
    if (isprime) {
      prime.push_back(i);
    }
  }
}

int main() {
  initprime();
  ll n;
  cin >> n;
  ll ans = 1;
  ll cur = 0;
  rep(i, n) {
    if (prime[i] * prime[i] > n)
      break;
    cur = prime[i];
    ll num = 1;
    while (ok(n, cur)) {
      cur *= prime[i];
      num++;
    }
    if (num > 1) {
      ans *= num;
    }
  }
  cout << ans + 1 << endl;
  return 0;
}