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

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

const ll maxs = 2e5 + 5;
const ll lmaxs = 20;
ll mod = 1e9 + 7;
ll oo = 1e15;

#define IOS                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(nullptr);                                                            \\
  cout.tie(nullptr);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define I insert
#define endl '\\n'

void pre() {}

void solve() {
  ll n, k, c;
  cin >> n >> k >> c;
  string s;
  cin >> s;
  vector<ll> a, b;
  for (ll i = 0; i < n; i++) {
    if (s[i] == 'o') {
      a.pb(i);
      i += c;
    }
  }
  for (ll i = n - 1; i >= 0; i--) {
    if (s[i] == 'o') {
      b.pb(i);
      i -= c;
    }
  }
  // reverse(b.begin(),b.end());
  vector<ll> ANS;
  for (ll i = 0; i < k; i++) {
    if (a[i] == b[k - i - 1]) {
      ANS.pb(a[i] + 1);
    }
  }

  for (auto it : ANS)
    cout << it << endl;
}

int main() {

  IOS;
  pre();
  ll T = 1;
  // cin>>T;
  while (T--) {
    solve();
  }
  return 0;
}

Error: -11

Fixed submission:

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

const ll maxs = 2e5 + 5;
const ll lmaxs = 20;
ll mod = 1e9 + 7;
ll oo = 1e15;

#define IOS                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(nullptr);                                                            \\
  cout.tie(nullptr);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define I insert
#define endl '\\n'

void pre() {}

void solve() {
  ll n, k, c;
  cin >> n >> k >> c;
  string s;
  cin >> s;
  vector<ll> a, b;
  for (ll i = 0; i < n; i++) {
    if (s[i] == 'o') {
      a.pb(i);
      i += c;
    }
  }
  for (ll i = n - 1; i >= 0; i--) {
    if (s[i] == 'o') {
      b.pb(i);
      i -= c;
    }
  }
  // reverse(b.begin(),b.end());
  vector<ll> ANS;
  for (ll i = 0; i < k; i++) {
    if (a[i] == b[k - i - 1]) {
      ANS.pb(a[i] + 1);
    }
  }

  for (auto it : ANS)
    cout << it << endl;
}

int main() {
#ifndef ONLINE_JUDGE
  freopen("input00.txt", "r", stdin);
#endif
  IOS;
  pre();
  ll T = 1;
  // cin>>T;
  while (T--) {
    solve();
  }
  return 0;
}
Problem p02721 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n, k, c;
  cin >> n >> k >> c;
  string s;
  cin >> s;

  if (n == 1) {
    cout << 1 << endl;
    return 0;
  }

  int dpl[n], dpr[n];

  dpl[0] = s[0] == 'o';
  for (int i = 1; i < n; ++i) {
    dpl[i] = dpl[i - 1];
    if (s[i] == 'o' && i - c - 1 >= 0) {
      dpl[i] = max(dpl[i], 1 + dpl[i - c - 1]);
    } else if (s[i] == 'o')
      dpl[i] = max(dpl[i], 1);
  }

  dpr[n - 1] = s[n - 1] == 'o';
  for (int i = n - 2; i >= 0; --i) {
    dpr[i] = dpr[i + 1];
    if (s[i] == 'o' && i + c + 1 < n) {
      dpr[i] = max(dpr[i], 1 + dpr[i + c + 1]);
    } else if (s[i] == 'o')
      dpr[i] = max(dpr[i], 1);
  }

  // assert(k == dpl[n-1] && dpr[0] == k);

  if (n > 1 && dpr[1] < k)
    cout << 1 << '\\n';

  for (int i = 1; i < n - 1; ++i) {
    if (dpl[i - 1] + dpr[i + 1] < k) {
      cout << i + 1 << '\\n';
    }
  }

  if (n > 1 && dpl[n - 2] < k)
    cout << n << '\\n';
}

Error: 0

Fixed submission:

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

int main() {
  int n, k, c;
  cin >> n >> k >> c;
  string s;
  cin >> s;

  int dpl[n], dpr[n];

  dpl[0] = s[0] == 'o';
  for (int i = 1; i < n; ++i) {
    dpl[i] = dpl[i - 1];
    if (s[i] == 'o' && i - c - 1 >= 0) {
      dpl[i] = max(dpl[i], 1 + dpl[i - c - 1]);
    } else if (s[i] == 'o')
      dpl[i] = max(dpl[i], 1);
  }

  dpr[n - 1] = s[n - 1] == 'o';
  for (int i = n - 2; i >= 0; --i) {
    dpr[i] = dpr[i + 1];
    if (s[i] == 'o' && i + c + 1 < n) {
      dpr[i] = max(dpr[i], 1 + dpr[i + c + 1]);
    } else if (s[i] == 'o')
      dpr[i] = max(dpr[i], 1);
  }

  assert(dpr[0] == dpl[n - 1] && dpr[0] == k);

  if (n > 1 && dpr[1] < k)
    cout << 1 << '\\n';

  for (int i = 1; i < n - 1; ++i) {
    if (dpl[i - 1] + dpr[i + 1] < k) {
      cout << i + 1 << '\\n';
    }
  }

  if (n > 1 && dpl[n - 2] < k)
    cout << n << '\\n';
}
Problem p02721 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>
using namespace std;
int main() {
  int n, k, c;
  string s;
  cin >> n >> k >> c >> s;
  int *l = new int[k];
  int *r = new int[k];
  for (int i = 0, ki = 0; i < n; i++) {
    if (s[i] == 'o') {
      l[ki++] = i;
      i += c;
      if (ki == k)
        break;
    }
  }
  for (int i = n - 1, ki = k - 1; i >= 0; i--) {
    if (s[i] == 'o') {
      r[ki--] = i;
      i -= c;
      if (ki == -1)
        break;
    }
  }
  for (int x = 0; x < k; x++) {
    if (l[x] == r[x])
      cout << l[x] + 1 << endl;
  }
  return 0;
}


Error: 0

Fixed submission:

#include <cstring>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
char *gs;
vector<string> l;
void f(char *s, int n, int k, int c) {
  if ((n <= 0) || (k < 0)) {
  } else if (k == 0) {
    for (int j = 0; j < n; j++)
      *s++ = '0';
    l.push_back(string(gs));
  } else if (n < (k - 1) * (c + 1) + 1) {
  } else if (n == (k - 1) * (c + 1) + 1) {
    for (int j = 0; j < k - 1; j++) {
      *s++ = '1';
      for (int i = 0; i < c; i++)
        *s++ = '0';
    }
    *s++ = '1';
    l.push_back(string(gs));
  } else {
    *s = '0';
    f(s + 1, n - 1, k, c);
    if (k == 1) {
      *s = '1';
      f(s + 1, n - 1, k - 1, c);
    } else {
      *s = '1';
      for (int i = 0; i < c; i++)
        s[i + 1] = '0';
      f(s + c + 1, n - c - 1, k - 1, c);
    }
  }
}
int main() {
  int n, k, c;
  string s;
  cin >> n >> k >> c >> s;
  gs = new char[n + 1];
  f(gs, n, k, c);
  char *ss = new char[n + 1];
  memset(ss, '1', n);
  ss[n + 1] = '\\0';
  for (auto a : l) {
    bool acc = true;
    for (int i = 0; i < a.length(); i++) {
      if (a[i] == '1' && (s[i] == 'x'))
        acc = false;
    }
    if (!acc)
      continue;
    for (int i = 0; i < a.length(); i++) {
      ss[i] = (ss[i] == '1') && (a[i] == '1') ? '1' : '0';
    }
    int d = 0;
  }
  for (int i = 0; i < n; i++) {
    if (ss[i] == '1')
      cout << i + 1 << endl;
  }
  return 0;
}
Problem p02721 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

void solve(int TestCase) {
  int n, k, c;
  cin >> n >> k >> c;
  string s;
  cin >> s;

  int cnt = 0;
  auto l = vector<int>(n);
  auto r = vector<int>(n);

  for (auto i = 0; i < n; ++i) {
    if (s[i] == 'o') {
      l[cnt++] = i;
      i += c;
    }
  }

  cnt = 0;
  for (auto i = n - 1; i >= 0; --i) {
    if (s[i] == 'o') {
      r[cnt++] = i;
      i -= c;
    }
  }

  for (auto i = 0; i < k; ++i) {
    if (l[i] == r[k - 1 - i])
      cout << (l[i] + 1) << endl;
  }
}

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

  int t = 1;
  // cin >> t;
  for (auto i = 1; i <= t; ++i) {
    //    cout << "Case #"<< i << ": ";
    solve(i);
  }
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

void solve(int TestCase) {
  int n, k, c;
  cin >> n >> k >> c;
  string s;
  cin >> s;

  int cnt = 0;
  auto l = vector<int>(k + 1);
  auto r = vector<int>(k + 1);

  for (auto i = 0; i < n; ++i) {
    if (s[i] == 'o')
      l[cnt++] = i;
    i += c;
  }

  cnt = 0;
  for (auto i = n - 1; i >= 0; --i) {
    if (s[i] == 'o')
      r[cnt++] = i;
    i -= c;
  }

  for (auto i = 0; i < k; ++i) {
    if (l[i] == r[k - 1 - i])
      cout << (l[i] + 1) << endl;
  }
}

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

  int t = 1;
  // cin >> t;
  for (auto i = 1; i <= t; ++i) {
    //    cout << "Case #"<< i << ": ";
    solve(i);
  }
}
Problem p02721 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int main() {
  ll n, k, c;
  cin >> n >> k >> c;
  string s;
  cin >> s;
  if (c == 0) {
    vector<ll> res;
    ll cnt = 0;
    rep(i, n) {
      if (s[i] == 'o') {
        res.push_back(i + 1);
        cnt++;
      }
    }
    if (cnt == k) {
      for (ll X : res)
        cout << X << endl;
    }
    return 0;
  }

  vector<ll> res1, res2;
  ll tmp = 0;
  while (true) {
    if (tmp >= n)
      break;
    else if (s[tmp] == 'x')
      tmp++;
    else {
      res1.push_back(tmp);
      tmp += c + 1;
    }
  }
  tmp = n - 1;
  while (true) {
    if (tmp < 0)
      break;
    else if (s[tmp] == 'x')
      tmp--;
    else {
      res2.push_back(tmp);
      tmp -= c + 1;
    }
  }
  map<ll, ll> m;
  for (ll x : res2)
    m[x]++;
  for (ll x : res1) {
    if (m[x] > 0)
      cout << x + 1 << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int main() {
  ll n, k, c;
  cin >> n >> k >> c;
  string s;
  cin >> s;
  vector<ll> res;
  rep(i, n) {
    if (s[i] == 'x')
      continue;
    ll cnt = 0;
    ll tmp = 0;
    while (true) {
      if (cnt >= k || tmp >= n)
        break;
      if (tmp == i)
        tmp++;
      else if (s[tmp] == 'x')
        tmp++;
      else {
        cnt++;
        tmp += c + 1;
      }
    }
    if (cnt < k)
      res.push_back(i + 1);
  }
  for (ll x : res) {
    cout << x << endl;
  }
  return 0;
}
Problem p02722 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define inf 1001001001
#define mod 1000000007
#define pi 3.141592653589793
ll gcd(ll a, ll b) {
  if (b > a)
    swap(a, b);
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
  ll g = gcd(a, b);
  return a / g * b;
}

ll rep_jijo(ll n, ll x) {
  if (x == 0)
    return 1;
  if (x % 2 == 0) {
    ll t = rep_jijo(n, x / 2);
    return t * t % mod;
  }
  return n * rep_jijo(n, x - 1) % mod;
}
ll com(ll n, ll r) {
  ll x = 1, y = 1;
  ll tmp = n;
  while (tmp >= n - r + 1) {
    x = x * tmp % mod;
    tmp--;
  }
  while (r > 0) {
    y = y * r % mod;
    r--;
  }
  return x * rep_jijo(y, mod - 2) % mod;
}

int main() {
  ll n;
  ll ans = 0;
  cin >> n;
  vector<ll> div_n;
  vector<ll> div_nm;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      div_n.push_back(i);
      if (i * i != n)
        div_n.push_back(n / i);
    }
  }
  for (ll i = 1; i * i <= n - 1; i++) {
    if ((n - 1) % i == 0) {
      div_nm.push_back(i);
      if (i * i != n - 1)
        div_nm.push_back((n - 1) / i);
    }
  }
  for (ll x : div_n) {
    if (x == 1)
      continue;
    ll tmp = n;
    while (tmp % x == 0)
      tmp /= x;
    if (tmp % x == 1)
      ans++;
  }
  ans += div_nm.size() - 1;
  cout << ans << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define inf 1001001001
#define mod 1000000007
#define pi 3.141592653589793
ll gcd(ll a, ll b) {
  if (b > a)
    swap(a, b);
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
  ll g = gcd(a, b);
  return a / g * b;
}
ll rep_jijo(ll n, ll x) {
  if (x == 0)
    return 1;
  if (x % 2 == 0) {
    ll t = rep_jijo(n, x / 2);
    return t * t;
  }
  return n * rep_jijo(n, x - 1);
}
ll com(ll n, ll r) {
  ll x = 1, y = 1;
  ll tmp = n;
  while (tmp >= n - r + 1) {
    x = x * tmp % mod;
    tmp--;
  }
  while (r > 0) {
    y = y * r % mod;
    r--;
  }
  return x * rep_jijo(y, mod - 2) % mod;
}

int main() {
  ll n;
  cin >> n;
  ll a, b;
  ll k = 2;
  ll ans = 0;
  while (k <= n) {
    for (a = 0; a <= 45; a++) {
      if (rep_jijo(k, a) > n)
        break;
      if (n % rep_jijo(k, a) != 0)
        continue;
      else {
        ll y = n / rep_jijo(k, a);
        y--;
        if (y % k == 0)
          ans++;
      }
    }
    k++;
  }
  cout << ans << endl;

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

#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream> //約数だけ考えればよいですね。O(sqrt(n))で解けます。
#include <queue>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
using ll = long long;
using namespace std;
vector<ll> enumDivisor(ll n) {
  vector<ll> a;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i != 0)
      continue;
    a.push_back(i);
    if (i * i != n)
      a.push_back(n / i);
  }

  return a;
}
int main() {
  ll n, ans = 0;
  cin >> n;
  for (ll x : enumDivisor(n)) {
    if (x == 1)
      continue;
    ll tmp = n;
    while (tmp % x == 0)
      tmp /= x;
    tmp %= x;
    if (tmp == 1)
      ans++;
  }
  ans += enumDivisor(n - 1).size() - 1;
  cout << ans;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
using ll = long long;
using namespace std;

int main() {
  ll n;
  int ans = 0;
  cin >> n;
  for (int k = 2; k < n + 1; k++) {
    ll nn = n;
    while (nn != 1) {
      ll tmp = nn % k;
      if (tmp == 0)
        nn /= k;

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

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

int main() {

  long long N;
  cin >> N;

  int ans = 0;
  for (long long i = 1; i * i <= N - 1; i++) {
    if ((N - 1) % i == 0)
      ans += 2;
    if (i * i == N - 1)
      ans--;
    if (i == 1)
      ans--;
  }

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

      if (i * i == N)
        continue;

      num = N;
      long long div = N / i;
      while (num % div == 0)
        num /= div;
      if (num % div == 1)
        ans++;
    }
  }

  cout << ans << endl;
}


Error: TLE

Fixed submission:

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

int main() {

  long long N;
  cin >> N;

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

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

  cout << ans << endl;
}
Problem p02722 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define FASTIO                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define PRECISION std::cout << std::fixed << std::setprecision(20);

using namespace std;

const ll inf = 1e18;
const ll N = 3e5 + 100;
const ll bits = 20;
const ld pi = 3.14159265358979323846;
const ll mod = 1e9 + 9;
const ll p = 29;

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

int main() {
  FASTIO;
  PRECISION;

  ll n;
  cin >> n;

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

  set<ll> ans;

  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);
      }
    }
  }
  ans.insert(n);
  n--;

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

  cout << ans.size() << "\\n";
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define FASTIO                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define PRECISION std::cout << std::fixed << std::setprecision(20);

using namespace std;

const ll inf = 1e18;
const ll N = 3e5 + 100;
const ll bits = 20;
const ld pi = 3.14159265358979323846;
const ll mod = 1e9 + 9;
const ll p = 29;

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

int main() {
  FASTIO;
  PRECISION;

  ll n;
  cin >> n;

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

  set<ll> ans;

  ll n2 = n - 1;

  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);
      }
    }

    if (n2 % i == 0) {
      ans.insert(i);
      ans.insert(n2 / i);
    }
  }
  ans.insert(n);
  ans.insert(n2);

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

#include <bits/stdc++.h>
#define bear ryan
#define fi first
#define se second
#define all(v) v.begin(), v.end()
#define pb push_back
#define eb emplace_back
#define endl '\\n'
#define ends ' '
#define fastio ios_base::sync_with_stdio(0), cin.tie(0)
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll inf = 1e9;

ll n, ans = 1;

int main(void) {
  fastio;
  cin >> n;
  ll t = n - 1;
  for (ll i = 2; i * i <= t; ++i) {
    int cnt = 0;
    while (t % i == 0) {
      ++cnt;
      t /= i;
    }
    ans *= (cnt + 1);
  }
  if (t != 1)
    ans *= 2;
  for (ll i = 2; i * i <= n; ++i)
    if (n % i == 0) {
      t = n;

      while (t % i == 0)
        t /= i;
      ans += (t % i == 1);
      if (i * i == n)
        continue;

      t = n;
      ll k = n / i;
      while (t && t % k == 0)
        t /= k;
      ans += (t % k == 1);
    }
  cout << ans;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define bear ryan
#define fi first
#define se second
#define all(v) v.begin(), v.end()
#define pb push_back
#define eb emplace_back
#define endl '\\n'
#define ends ' '
#define fastio ios_base::sync_with_stdio(0), cin.tie(0)
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll inf = 1e9;

ll n, ans = 1;

int main(void) {
  fastio;
  cin >> n;
  ll t = n - 1;
  for (int i = 2; t != 1; ++i) {
    int cnt = 0;
    while (t % i == 0) {
      ++cnt;
      t /= i;
    }
    ans *= (cnt + 1);
  }
  for (ll i = 2; i * i <= n; ++i)
    if (n % i == 0) {
      t = n;
      while (t && t % i == 0)
        t /= i;
      ans += (t % i == 1);
      if (i * i == n)
        continue;

      t = n;
      ll k = n / i;
      while (t && t % k == 0)
        t /= k;
      ans += (t % k == 1);
    }
  cout << ans;
  return 0;
}
Problem p02722 (C++) — buggy submission, verdict: Runtime Error


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

int yakusuu(long long a) {
  int count = 0;
  for (int i = 2; i <= sqrt(a); i++) {
    if (a % i == 0) {
      if (i == sqrt(a))
        count++;
      else
        count += 2;
    }
  }
  count++;
  return count;
}

int main() {
  long long n;
  cin >> n;
  long long count = 0;
  count += yakusuu(n - 1);
  if (n == 2) {
    cout << 1;
    return 0;
  }
  for (int i = 2; i <= sqrt(n); i++) {
    long long a = n;
    while (a % i == 0) {
      a /= i;
      if (a == 1) {
        count++;
        break;
      }
    }
  }
  for (int i = 2; i <= sqrt(n); i++) {
    long long a = n;

    if (a % i != 0)
      continue;
    while (a % i == 0) {
      a /= i;
    }
    if (a == 1)
      continue;
    if ((a - 1) % i == 0)
      count++;
  }
  cout << count + 1;
  return 0;
}

Error: WA

Fixed submission:


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

int yakusuu(long long a) {
  int count = 0;
  for (int i = 2; i <= sqrt(a); i++) {
    if (a % i == 0) {
      if (i == sqrt(a))
        count++;
      else
        count += 2;
    }
  }
  count++;
  return count;
}

int main() {
  long long n;
  cin >> n;
  long long count = 0;
  count += yakusuu(n - 1);
  if (n == 2) {
    cout << 1;
    return 1;
  }
  for (int i = 2; i <= sqrt(n); i++) {
    long long a = n;
    while (a % i == 0) {
      a /= i;
      if (a == 1) {
        count++;
        break;
      }
    }
  }
  for (int i = 2; i <= sqrt(n); i++) {
    long long a = n;

    if (a % i != 0)
      continue;
    while (a % i == 0) {
      a /= i;
    }
    if (a == 1)
      continue;
    if ((a - 1) % i == 0)
      count++;
  }
  cout << count + 1;
  return 0;
}
Problem p02722 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define endl '\\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
// const int mod=1e9+7;
const int mod = 998244353;
const double eps = 1e-10;
const double pi = acos(-1.0);
const int maxn = 1e6 + 10;
const ll inf = 0x3f3f3f3f;
const int dir[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  // freopen("in.txt","r",stdin);
  // freopen("out.txt","w",stdout);
  ll n, t;
  cin >> n;
  int ans = 0;
  for (ll i = 1; i * i <= n - 1; i++) {
    if ((n - 1) % i == 0) {
      if (i != 1)
        ans++;
      if ((n - 1) / i != i)
        ans++;
    }
  }

  for (ll i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      t = n;
      while (t % i == 0)
        t /= i;
      if (t % i == 1)
        ans++;
    }
  }
  cout << ans + 1;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define endl '\\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
// const int mod=1e9+7;
const int mod = 998244353;
const double eps = 1e-10;
const double pi = acos(-1.0);
const int maxn = 1e6 + 10;
const ll inf = 0x3f3f3f3f;
const int dir[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  // freopen("in.txt","r",stdin);
  // freopen("out.txt","w",stdout);
  ll n, t;
  cin >> n;
  if (n == 2) {
    cout << 1;
    return 0;
  }
  int ans = 0;
  for (int i = 1; i * i <= n - 1; i++) {
    if ((n - 1) % i == 0) {
      if (i != 1)
        ans++;
      if ((n - 1) / i != i)
        ans++;
    }
  }
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      t = n;
      while (t % i == 0)
        t /= i;
      if (t % i == 1)
        ans++;
    }
  }
  cout << ans + 1;
  return 0;
}