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

#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;
typedef long double ld;
const ll MOD = 1000000007;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
long long gcd(long long a, long long b) {
  ll gcdmax = max(a, b);
  ll gcdmin = min(a, b);
  while (true) {
    if (gcdmax % gcdmin == 0)
      break;
    else
      gcdmax %= gcdmin;
    swap(gcdmin, gcdmax);
  }
  return gcdmin;
}
ll powerup(ll N, ll P, ll M) {
  if (P == 0)
    return 1;
  else if (P % 2 == 0) {
    ll t = powerup(N, P / 2, M);
    return t * t % M;
  } else
    return N * powerup(N, P - 1, M) % M;
}
vector<ll> find_divisor(ll N) {
  ll k = 1;
  while (k * k <= N) {
    k++;
  }
  vector<ll> A(1);
  rep(i, k) {
    if (i == 1)
      A.at(0) = 1;
    else if (i >= 2) {
      if (N % i == 0)
        A.push_back(i);
    }
  }
  ll t = 0;
  t = A.size();
  rep(i, t) {
    if (A.at(t - i - 1) * A.at(t - i - 1) != N)
      A.push_back(N / A.at(t - 1 - i));
  }
  return A;
}
int main() {
  ll N;
  cin >> N;
  vector<ll> A = find_divisor(N);
  vector<ll> B = find_divisor(N - 1);
  ll S = A.size();
  ll t = N;
  ll ans = 0;
  rep(i, S) {
    t = N;
    if (i >= 1) {
      while (true) {
        if (t % A.at(i) == 0)
          t /= A.at(i);
        else {
          t = t % A.at(i);
          break;
        }
      }
      if (t == 1) {
        ans++;
      }
    }
  }
  cout << ans + B.size() - 1 << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;
typedef long double ld;
const ll MOD = 1000000007;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
long long gcd(long long a, long long b) {
  ll gcdmax = max(a, b);
  ll gcdmin = min(a, b);
  while (true) {
    if (gcdmax % gcdmin == 0)
      break;
    else
      gcdmax %= gcdmin;
    swap(gcdmin, gcdmax);
  }
  return gcdmin;
}
ll powerup(ll N, ll P, ll M) {
  if (P == 0)
    return 1;
  else if (P % 2 == 0) {
    ll t = powerup(N, P / 2, M);
    return t * t % M;
  } else
    return N * powerup(N, P - 1, M) % M;
}
int main() {
  ll N;
  cin >> N;
  ll k = 0;
  while ((k + 1) * (k + 1) < N) {
    k++;
  }
  vector<ll> A(1);
  rep(i, k + 1) {
    if (i == 1)
      A.at(0) = 1;
    else if (i >= 2) {
      if (N % i == 0)
        A.push_back(i);
    }
  }
  ll t = 0;
  t = A.size();
  rep(i, t) {
    if (A.at(t - i - 1) * A.at(t - i - 1) != N)
      A.push_back(N / A.at(t - 1 - i));
  }
  ll s;
  ll ans = 0;
  t = A.size();
  rep(i, t - 1) {
    s = N;
    if (i >= 1) {
      while (s > A.at(i)) {
        if (s % A.at(i) == 0)
          s /= A.at(i);
        else
          s = s % A.at(i);
      }
      if (s == 1)
        ans++;
    }
  }
  N--;
  k = 0;
  while ((k + 1) * (k + 1) < N) {
    k++;
  }
  vector<ll> B(1);
  rep(i, k + 1) {
    if (i == 1)
      B.at(0) = 1;
    else if (i >= 2) {
      if (N % i == 0)
        B.push_back(i);
    }
  }
  t = B.size();
  rep(i, t) {
    if (B.at(t - i - 1) * B.at(t - i - 1) != N)
      B.push_back(N / B.at(t - 1 - i));
  }
  t = B.size();
  cout << ans + t << endl;
}
Problem p02722 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define debug1 cout << "?" << endl;
#define debug2 cout << "?" << i << endl
#define PII pair<int, int>
typedef long long ll;
const int maxn = 2e5 + 9;
const double pi = acos(-1);
const int mod = 1e9 + 7;
const int INF = 1e9;
const double ep = 1e-7;
using namespace std;
int main() {
  ll n;
  scanf("%lld", &n);
  if (n == 2) {
    puts("1");
    return 0;
  }
  ll k = n, i, j, yz[maxn] = {0}, cnt1 = 0;
  for (i = 2; i * i <= k; i++) {
    if (k % i == 0) {
      yz[++cnt1] = i;
      if (i * i != k)
        yz[++cnt1] = k / i;
    }
  }
  ll ans = 1;
  map<ll, bool> mp;
  mp[n] = 1;
  k -= 1;
  for (i = 2; i * i <= k; i++) {
    if (k % i == 0) {
      mp[i] = 1, ans++;
      if (i * i != k) {
        mp[k / i] = 1, ans++;
      }
    }
  }
  for (i = 1; i <= cnt1; i++) {
    k = n;
    if (mp[yz[i]])
      continue;
    while (k % yz[i] == 0)
      k /= yz[i];
    if (k % yz[i] == 1)
      ans++;
  }
  if (mp[1])
    ans--;
  if (!mp[n - 1])
    ans++;
  printf("%lld\\n", ans);
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define debug1 cout << "?" << endl;
#define debug2 cout << "?" << i << endl
#define PII pair<int, int>
typedef long long ll;
const int maxn = 2e3 + 9;
const double pi = acos(-1);
const int mod = 1e9 + 7;
const int INF = 1e9;
const double ep = 1e-7;
using namespace std;
int main() {
  ll n;
  scanf("%lld", &n);
  ll k = n, i, j, yz[maxn] = {0}, cnt1 = 0;
  for (i = 2; i * i <= k; i++) {
    if (k % i == 0) {
      yz[++cnt1] = i;
      if (i * i != k)
        yz[++cnt1] = k / i;
    }
  }
  ll ans = 1;
  map<ll, bool> mp;
  mp[n] = 1;
  k -= 1;
  for (i = 2; i * i <= k; i++) {
    if (k % i == 0) {
      mp[i] = 1, ans++;
      if (i * i != k) {
        mp[k / i] = 1, ans++;
      }
    }
  }
  for (i = 1; i <= cnt1; i++) {
    k = n;
    if (mp[yz[i]])
      continue;
    while (k % yz[i] == 0)
      k /= yz[i];
    if (k % yz[i] == 1)
      ans++;
  }
  if (mp[1])
    ans--;
  if (!mp[n - 1])
    ans++;
  printf("%lld\\n", ans);
}
Problem p02722 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
bool can(ll x, ll p) {
  while (x % p == 0) {
    x /= p;
  }
  return x % p == 1;
}
set<ll> s;
int main() {
  ll n;
  scanf("%lld", &n);
  ll m = n - 1;
  for (ll i = 1; i * i <= m; i++) {
    if (m % i == 0) {
      s.insert(m / i);
      s.insert(i);
    }
  }
  for (ll i = 1; i * i <= n; i++) {
    if (i != 1)
      if (can(n, i))
        s.insert(i);
    if ((n / i) != 1)
      if (can(n, n / i))
        s.insert(n / i);
  }
  s.erase(1);
  printf("%d\\n", s.size());
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
bool can(ll x, ll p) {
  while (x % p == 0) {
    x /= p;
  }
  return x % p == 1;
}
set<ll> s;
int main() {
  ll n;
  scanf("%lld", &n);
  ll m = n - 1;
  for (int i = 1; i * i <= m; i++) {
    if (m % i == 0) {
      s.insert(m / i);
      s.insert(i);
    }
  }
  for (int i = 1; i * i <= n; i++) {
    if (i != 1)
      if (can(n, i))
        s.insert(i);
    if ((n / i) != 1)
      if (can(n, n / i))
        s.insert(n / i);
  }
  // s.erase(1);
  printf("%d\\n", s.size() - 1);
}
Problem p02722 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
long long k, ans = 0;
map<long long, bool> vis;
void fun(long long x) {

  if (x == 1)
    return;
  long long y = k;
  while (y % x == 0)
    y /= x;
  y %= x;
  if (y == 1) {
    if (!vis[x]) {
      ans++;
      vis[x] = 1;
    }
  }
}
int main() {
  cin >> k;
  for (long long i = 1; i * i <= k; i++) {
    if (k % i == 0) {
      fun(i);
      fun(k / i);
    }
  }
  for (long long i = 1; i * i <= k - 1; i++) {
    if ((k - 1) % i == 0) {
      fun(i);
      fun((k - 1) / i);
    }
  }
  cout << ans;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
long long k, ans;
map<long long, bool> vis;
void fun(long long x) {
  if (x == 1)
    return;
  long long y = k;
  while (y % x == 0)
    y /= x;
  y %= x;
  if (y == 1) {
    if (!vis[x]) {
      ans++;
      vis[x] = 1;
    }
  }
}
int main() {
  cin >> k;
  for (int i = 1; i * i <= k; i++) {
    if (k % i == 0) {
      fun(i);
      fun(k / i);
    }
  }
  for (int i = 1; i * i <= k - 1; i++) {
    if ((k - 1) % i == 0) {
      fun(i);
      fun((k - 1) / i);
    }
  }
  cout << ans;
  return 0;
}
Problem p02722 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using ll = int_fast64_t;

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

int main() {
  ll n;
  scanf("%ld", &n);

  std::set<ll> st;
  ll m = n;
  for (ll i = 2; i * i <= m; i++) {
    if (m % i == 0) {
      st.insert(i);
      if (i * i != m)
        st.insert(m / i);
    }
  }

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

  ll ans = 1 + (n != 2);
  for (ll i : st)
    ans += judge(n, i);
  printf("%ld\\n", ans);
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using ll = int_fast64_t;

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

int main() {
  ll n, ans = 0;
  scanf("%ld", &n);

  std::set<ll> st({n, n - 1});
  ll m = n;
  for (ll i = 2; i * i <= m; i++) {
    if (m % i == 0) {
      st.insert(i);
      if (i * i != m)
        st.insert(m / i);
    }
  }

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

  for (ll i : st)
    ans += judge(n, i);
  printf("%ld\\n", ans);
  return 0;
}
Problem p02722 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define all(a) (a).begin(), (a).end()
#define debug(x) cerr << (#x) << ": " << (x) << endl

typedef long long ll;

bool check(ll n, ll k) {
  if (n == 1)
    return true;
  if (n < k)
    return false;
  if (n % k == 0) {
    return check(n / k, k);
  } else {
    return check(n % k, k);
  }
}

vector<ll> get_div(ll n) {
  vector<ll> res;
  for (ll d = 2; d * d <= n; d++) {
    if (n % d == 0) {
      res.push_back(d);
      if (d < n / d) {
        res.push_back(n / d);
      }
    }
  }
  return res;
}

int main(void) {
  ll n;
  cin >> n;
  if (n == 2) {
    cout << 1 << endl;
    return 0;
  }
  vector<ll> cand = {n, n - 1};
  auto div1 = get_div(n);
  cand.insert(cand.end(), all(div1));
  auto div2 = get_div(n - 1);
  cand.insert(cand.end(), all(div2));
  set<ll> res;
  for (ll d : cand) {
    if (check(n, d))
      res.insert(d);
  }
  cout << res.size() << endl;
  return 0;
}


Error: -6
terminate called after throwing an instance of 'std::length_error'
  what():  vector::_M_range_insert


Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define all(a) (a).begin(), (a).end()

typedef long long ll;

bool check(ll n, ll k) {
  if (n == 1)
    return true;
  if (n < k)
    return false;
  if (n % k == 0) {
    return check(n / k, k);
  } else {
    return check(n % k, k);
  }
}

vector<ll> get_div(ll n) {
  vector<ll> res;
  for (ll d = 2; d * d <= n; d++) {
    if (n % d == 0) {
      res.push_back(d);
      if (d < n / d) {
        res.push_back(n / d);
      }
    }
  }
  return res;
}

int main(void) {
  ll n;
  cin >> n;
  if (n == 2) {
    cout << 1 << endl;
    return 0;
  }
  vector<ll> cand = {n, n - 1};
  cand.insert(cand.end(), all(get_div(n)));
  cand.insert(cand.end(), all(get_div(n - 1)));
  set<ll> res;
  for (ll d : cand) {
    if (check(n, d))
      res.insert(d);
  }
  cout << res.size() << endl;
  return 0;
}
Problem p02722 (C++) — buggy submission, verdict: Time Limit Exceeded

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

bool check(ll n, ll k) {
  if (n == 1)
    return true;
  if (n < k)
    return false;
  if (n % k == 0) {
    return check(n / k, k);
  } else {
    return check(n % k, k);
  }
}

vector<ll> get_div(ll n) {
  vector<ll> res;
  for (ll d = 2; d * d <= n; d++) {
    if (n % d == 0) {
      res.push_back(d);
      if (d < n / d) {
        res.push_back(n / d);
      }
    }
  }
  return res;
}

int main(void) {
  ll n;
  cin >> n;
  if (n == 2) {
    cout << 1 << endl;
    return 0;
  }
  set<ll> res;
  auto divs = get_div(n);
  for (ll d : divs) {
    if (check(n, d))
      res.insert(d);
  }
  auto divs2 = get_div(n - 1);
  for (ll d : divs2) {
    if (check(n, d))
      res.insert(d);
  }
  if (check(n, n))
    res.insert(n);
  if (check(n, n - 1))
    res.insert(n - 1);
  cout << res.size() << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

bool check(ll n, ll k) {
  if (n == 1)
    return true;
  if (n < k)
    return false;
  if (n % k == 0) {
    return check(n / k, k);
  } else {
    return check(n % k, k);
  }
}

vector<ll> get_div(ll n) {
  vector<ll> res;
  for (ll d = 2; d * d <= n; d++) {
    if (n % d == 0) {
      res.push_back(d);
      if (d < n / d) {
        res.push_back(n / d);
      }
    }
  }
  return res;
}

int main(void) {
  ll n;
  cin >> n;
  set<ll> res;
  auto divs = get_div(n);
  for (ll d : divs) {
    if (check(n, d))
      res.insert(d);
  }
  auto divs2 = get_div(n - 1);
  for (ll d : divs2) {
    if (check(n, d))
      res.insert(d);
  }
  if (check(n, n))
    res.insert(n);
  if (check(n, n - 1))
    res.insert(n - 1);
  cout << res.size() << endl;
  return 0;
}
Problem p02722 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vpii = vector<pii>;
using vpll = vector<pll>;

#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++)
int INF = 1e9 + 7;

vl divisor(ll n) {
  vl div;
  for (ll i = 1; i * i <= n; i++) {
    if (i * i < n && !(n % i)) {
      div.push_back(i);
      div.push_back(n / i);
    } else if (i * i == n)
      div.push_back(i);
  }
  return div;
}

int main() {
  ll N;
  cin >> N;
  int ans = 0;
  vl div = divisor(N);
  for (ll x : div) {
    if (x == 1)
      continue;
    ll num = N;
    while (!(num % x))
      num /= x;
    ans += (num % x == 1);
  }
  ans += divisor(N - 1).size();
  cout << --ans << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vpii = vector<pii>;
using vpll = vector<pll>;

#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++)
int INF = 1e9 + 7;

vl divisor(ll n) {
  vl div;
  for (ll i = 1; i * i <= n; i++) {
    if (i * i < n && !(n % i)) {
      div.push_back(i);
      div.push_back(n / i);
    } else if (i * i == n)
      div.push_back(i);
  }
  return div;
}

int main() {
  ll N;
  cin >> N;
  int ans = 0;
  vl div = divisor(N);
  for (int x : div) {
    if (x == 1)
      continue;
    int num = N;
    while (!(num % x))
      num /= x;
    ans += (num % x == 1);
  }
  ans += divisor(N - 1).size();
  cout << --ans << endl;
}
Problem p02722 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
vector<ll> enumDivisor(ll x) {
  vector<ll> res;
  for (ll i = 1; i * i <= x; ++i) {
    if (x % i)
      continue;
    res.push_back(i);
    if (i * i != x)
      res.push_back(x / i);
  }
  return res;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  ll n;
  cin >> n;
  int ans = 0;
  for (auto x : enumDivisor(n)) {
    if (x == 1)
      continue;
    ll tmp = n;
    while (tmp % x == 0)
      tmp /= x;
    if (tmp % x == 1)
      ++ans;
  }
  ans += enumDivisor(n - 1).size() - 1;
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
vector<ll> enumDivisor(ll x) {
  vector<ll> res;
  for (int i = 1; i * i <= x; ++i) {
    if (x % i)
      continue;
    res.push_back(i);
    if (i * i != x)
      res.push_back(x / i);
  }
  return res;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  ll n;
  cin >> n;
  int ans = 0;
  for (auto x : enumDivisor(n)) {
    if (x == 1)
      continue;
    ll tmp = n;
    while (tmp % x == 0)
      tmp /= x;
    if (tmp % x == 1)
      ++ans;
  }
  ans += enumDivisor(n - 1).size() - 1;
  cout << ans << endl;
}
Problem p02722 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
long long n, ans;
void f(int x) {
  long long nn = n;
  while (nn % x == 0)
    nn /= x;
  if (nn % x == 1)
    ++ans;
}
int main() {
  // freopen("F.in","r",stdin);
  // freopen("F.out","w",stdout);

  scanf("%lld", &n);

  ans = 0;
  for (long long i = 1; i * i <= n; ++i) {
    if ((n - 1) % i == 0) {
      ++ans;
      if (i * i != n - 1)
        ++ans;
    }
  }

  for (long long i = 2; i * i <= n; ++i)
    if (n % i == 0)
      f(i);

  printf("%lld\\n", ans);

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
long long n, ans;
void f(int x) {
  long long nn = n;
  while (nn % x == 0)
    nn /= x;
  if (nn % x == 1)
    ++ans;
}
int main() {
  // freopen("F.in","r",stdin);
  // freopen("F.out","w",stdout);

  scanf("%lld", &n);

  ans = 0;
  for (int i = 1; i * i <= n - 1; ++i) {
    if ((n - 1) % i == 0) {
      ++ans;
      if (i * i != n - 1)
        ++ans;
    }
  }

  for (int i = 2; i * i <= n; ++i)
    if (n % i == 0)
      f(i);

  printf("%lld\\n", ans);

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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 998244353;
const int maxn = 2e5 + 10;
map<int, bool> vis;
ll n, ans;
ll solve1(ll x) {
  ll res = 1;
  vis[x] = true;
  for (ll i = 2; i * i <= x; i++) {
    if (x % i != 0)
      continue;
    ll j = x / i, xx = x;
    if (!vis[i]) {
      while (xx % i == 0)
        xx /= i;
      if (xx % i == 1)
        res++;
      vis[i] = true;
    }
    if (!vis[j]) {
      xx = x;
      while (xx % j == 0)
        xx /= j;
      if (xx % j == 1)
        res++;
      vis[j] = true;
    }
  }
  return res;
}
ll solve2(ll x) {
  ll res = 1;
  vis.clear();
  vis[x] = true;
  for (ll i = 2; i * i <= x; i++) {
    if (x % i != 0)
      continue;
    ll j = x / i;
    if (!vis[i])
      vis[i] = true, res++;
    if (!vis[j])
      vis[j] = true, res++;
  }
  return res;
}
int main() {
  // freopen("/Users/zhangkanqi/Desktop/11.txt","r",stdin);
  scanf("%lld", &n);
  if (n == 2)
    printf("1\\n");
  else
    printf("%lld\\n", solve1(n) + solve2(n - 1));
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 998244353;
const int maxn = 2e5 + 10;
map<int, int> cnt;
map<int, bool> vis;
vector<ll> fac;
ll n, ans = 1;
bool check(ll v) {
  ll x = sqrt(v);
  for (ll i = 2; i <= x; i++)
    if (v % i == 0)
      return true;
  return false;
}
void div(ll x) {
  for (ll i = 2; i * i <= x; i++) {
    if (x % i == 0) {
      int num = 0;
      while (x % i == 0)
        num++, x /= i;
      cnt[i] = num, fac.push_back(i);
    }
    if (!check(x))
      break;
  }
  if (x != 1)
    cnt[x] = 1, fac.push_back(x);
}

int main() {
  // freopen("/Users/zhangkanqi/Desktop/11.txt","r",stdin);
  scanf("%lld", &n);
  div(n - 1);
  ll cas = 1;
  for (auto e : fac)
    cas *= (cnt[e] + 1);
  ans += (cas - 1);
  vis[n] = true;
  for (ll i = 2; i <= sqrt(n); i++) {
    if (n % i != 0)
      continue;
    ll j = n / i, x = n;
    while (x % i == 0)
      x /= i;
    if (x % i == 1)
      ans++;
    vis[i] = true;
    if (!vis[j]) {
      x = n;
      while (x % j == 0)
        x /= j;
      if (x % j == 1)
        ans++;
    }
    vis[j] = true;
  }
  printf("%lld\\n", ans);
  return 0;
}
Problem p02722 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline cerr << __LINE__ << endl;

using ll = long long;
template <class T, class U> using P = pair<T, U>;
template <class T> using Heap = priority_queue<T>;
template <class T> using heaP = priority_queue<T, vector<T>, greater<T>>;
template <class T, class U> using umap = unordered_map<T, U>;
template <class T> using uset = unordered_set<T>;

template <class T> bool ChangeMax(T &a, const T &b) {
  if (a >= b)
    return false;
  a = b;
  return true;
}

template <class T> bool ChangeMin(T &a, const T &b) {
  if (a <= b)
    return false;
  a = b;
  return true;
}

template <class T, size_t N, class U> void Fill(T (&a)[N], const U &v) {
  fill((U *)a, (U *)(a + N), v);
}

template <class T> istream &operator>>(istream &is, vector<T> &v) {
  for (auto &e : v)
    is >> e;
  return is;
}

int main() {
  ll n;
  cin >> n;
  set<ll> d;
  d.insert(n);
  if (n > 2)
    d.insert(n - 1);
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0)
      d.insert(i);
    if ((n - 1) % i == 0) {
      d.insert(i);
      if ((n - 1) / i > 1)
        d.insert((n - 1) / i);
    }
  }
  int cnt = 0;
  for (auto e : d) {
    ll x = n;
    while (x % e == 0)
      x /= e;
    cnt += x % e == 1;
  }
  cout << cnt << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline cerr << __LINE__ << endl;

using ll = long long;
template <class T, class U> using P = pair<T, U>;
template <class T> using Heap = priority_queue<T>;
template <class T> using heaP = priority_queue<T, vector<T>, greater<T>>;
template <class T, class U> using umap = unordered_map<T, U>;
template <class T> using uset = unordered_set<T>;

template <class T> bool ChangeMax(T &a, const T &b) {
  if (a >= b)
    return false;
  a = b;
  return true;
}

template <class T> bool ChangeMin(T &a, const T &b) {
  if (a <= b)
    return false;
  a = b;
  return true;
}

template <class T, size_t N, class U> void Fill(T (&a)[N], const U &v) {
  fill((U *)a, (U *)(a + N), v);
}

template <class T> istream &operator>>(istream &is, vector<T> &v) {
  for (auto &e : v)
    is >> e;
  return is;
}

int main() {
  ll n;
  cin >> n;
  set<ll> d;
  d.insert(n);
  if (n > 2)
    d.insert(n - 1);
  for (int i = 2; i * i <= n; ++i) {
    if (n % i == 0)
      d.insert(i);
    if ((n - 1) % i == 0) {
      d.insert(i);
      if ((n - 1) / i > 1)
        d.insert((n - 1) / i);
    }
  }
  int cnt = 0;
  for (auto e : d) {
    ll x = n;
    while (x % e == 0)
      x /= e;
    cnt += x % e == 1;
  }
  cout << cnt << 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++)
#define int long long

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

  int m = n;
  set<int> st;
  for (int t = 0; t < 2; t++) {
    for (int i = 2; i * i <= n; i++) {
      if (n % i == 0) {
        st.insert(i);
        st.insert(n / i);
      }
    }
    st.insert(n);
    n--;
  }

  st.erase(1);

  int answer = 0;
  for (auto &k : st) {
    int x = m;
    while (true) {
      if (x % k == 0)
        x /= k;
      else if (x % k == 1) {
        answer++;
        break;
      } else {
        break;
      }
    }
  }
  cout << answer << '\\n';
}


Error: TLE

Fixed submission:

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

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

  int m = n;
  set<int> st;
  for (int t = 0; t < 2; t++) {
    for (int i = 2; i * i <= n; i++) {
      if (n % i == 0) {
        st.insert(i);
        st.insert(n / i);
      }
    }
    st.insert(n);
    n--;
  }

  int answer = 0;
  for (auto &k : st) {
    int x = m;
    while (x >= 1) {
      if (x % k == 0)
        x /= k;
      else if (x % k == 1) {
        answer++;
        break;
      } else {
        break;
      }
    }
  }
  cout << answer << '\\n';
}