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

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define ALL(c) (c).begin(), (c).end()
#define pb push_back
#define eb emplace_back
using namespace std;
const long long INF = 1LL << 60; // 仮想的な無限大の値;
using ll = long long;
using P = pair<int, int>;
#define vi vector<int>
#define vll vector<ll>
#define vs vector<string>
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
// const int mod = 1000000007;

vector<pair<long long, long long>> prime_factorize(long long N) {
  vector<pair<long long, long long>> res;
  for (long long a = 2; a * a <= N; ++a) {
    if (N % a != 0)
      continue;
    long long ex = 0; // 指数

    // 割れる限り割り続ける
    while (N % a == 0) {
      ++ex;
      N /= a;
    }

    // その結果を push
    res.push_back({a, ex});
  }

  // 最後に残った数について
  if (N != 1)
    res.push_back({N, 1});
  return res;
}

int main() {
  int N;
  cin >> N;
  int ans = 0;
  rep2(i, 1, N) {
    int a = N / i;
    int b = N % i;
    if (b != 0) {
      ans += a;
      // if(a >=i) --ans;
    } else {
      --a;
      ans += a;
      // if(a >=i) --ans;
    }
  }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define ALL(c) (c).begin(), (c).end()
#define pb push_back
#define eb emplace_back
using namespace std;
const long long INF = 1LL << 60; // 仮想的な無限大の値;
using ll = long long;
using P = pair<int, int>;
#define vi vector<int>
#define vll vector<ll>
#define vs vector<string>
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
// const int mod = 1000000007;

vector<pair<long long, long long>> prime_factorize(long long N) {
  vector<pair<long long, long long>> res;
  for (long long a = 2; a * a <= N; ++a) {
    if (N % a != 0)
      continue;
    long long ex = 0; // 指数

    // 割れる限り割り続ける
    while (N % a == 0) {
      ++ex;
      N /= a;
    }

    // その結果を push
    res.push_back({a, ex});
  }

  // 最後に残った数について
  if (N != 1)
    res.push_back({N, 1});
  return res;
}

int main() {
  int N;
  cin >> N;
  int ans = 0;
  rep2(i, 1, N) {
    int x = i;
    if (x == 1) {
      ++ans;
      continue;
    }
    // if(x <= 3){
    //     ans += 2;continue;
    // }
    ans += 2;
    for (ll a = 2; a * a <= x; ++a) {
      if (x % a != 0)
        continue;
      if (a * a == x) {
        ++ans;
        continue;
      }
      ans += 2;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using ll = long long;
using ull = unsigned long long;
using namespace std;
constexpr int inf = 1 << 30;
constexpr int mo = 1e9 + 7;
constexpr ll infl = 1ll << 60;

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

  int n;
  cin >> n;
  int pat = 0;
  for (int a = 1; a < n; ++a) {
    pat += (n - 1) / a;
  }
  cout << pat << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using ll = long long;
using ull = unsigned long long;
using namespace std;
constexpr int inf = 1 << 30;
constexpr int mo = 1e9 + 7;
constexpr ll infl = 1ll << 60;

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

  int n;
  cin >> n;
  int pat = 0;
  for (int c = 1; c <= n; ++c) {
    int tmp = n - c;
    for (int a = 1; a * a <= tmp; ++a)
      if (tmp % a == 0) {
        if (a != tmp / a)
          pat += 2;
        else
          pat++;
      }
  }
  cout << pat << endl;
  return 0;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
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;
}
// const ll INF = 1LL << 60;
// const int INF = 1001001001;

int main(void) {
  int n;
  cin >> n;
  ll ans = 0;
  for (int a = 1; a < n; a++) {
    int bs = (n - 1) / a;
    ans += bs;
  }
  cout << ans;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
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;
}
// const ll INF = 1LL << 60;
// const int INF = 1001001001;
vector<int64_t> divisor(int64_t n) {
  vector<int64_t> ret;
  for (int64_t i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n)
        ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}
vector<bool> prime_table(int n) {
  vector<bool> prime(n + 1, true);
  if (n >= 0)
    prime[0] = false;
  if (n >= 1)
    prime[1] = false;
  for (int i = 2; i * i <= n; i++) {
    if (!prime[i])
      continue;
    for (int j = i + i; j <= n; j += i) {
      prime[j] = false;
    }
  }
  return prime;
}

int main(void) {
  int n;
  cin >> n;
  ll ans = 0;
  auto p = prime_table(n);
  for (int ab = 1; ab <= n - 1; ab++) {
    if (p[ab]) {
      ans += 2;
      continue;
    }
    auto v = divisor(ab);
    ans += v.size();
  }
  cout << ans;
  return 0;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using namespace std;

typedef pair<int, int> p;
typedef long long ll;
const int inf = 1000000007;

int main() {
  int n;
  cin >> n;
  ll res = 0;
  for (int c = 1; c <= n - 1; c++) {
    ll ans = 1;
    ll ab = n - c;
    for (int i = 2; i * i <= ab; i++) {
      ll cnt = 0;
      while (ab % i == 0) {
        cnt++;
        ab /= i;
      }
      ans *= (cnt + 1);
      // ans += cnt;
    }
    if (ab != 1)
      ans *= 2;
    // ans += cnt;
    res += ans;
  }
  cout << res << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

using namespace std;

typedef pair<int, int> p;
typedef long long ll;
const int inf = 1000000007;

int main() {
  int n;
  cin >> n;
  ll ans = 0;
  for (int c = 1; c <= n - 1; c++) {
    ll ab = n - c;
    ll cnt = 0;
    for (int i = 1; i * i <= ab; i++) {
      // int cnt = 2;
      if (ab % i == 0) {
        if (i == ab / i)
          cnt += 1;
        else
          cnt += 2;
      }
      // ans += cnt;
    }
    ans += cnt;
  }
  cout << ans << endl;
  return 0;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

  ll i, j, t, n, a, b, c, ans = 0;

  cin >> n;
  for (i = 1; i < n; i++) {
    for (j = 1; i * j < n; j++) {
      ans++;
    }
  }

  cout << ans << endl;
}

Error: TLE

Fixed submission:

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

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

  ll i, j, t, n, a, b, c, ans = 0;

  cin >> n;
  for (i = 1; i <= n - 1; i++) {
    for (j = 1; j <= sqrt(n - i); j++) {
      if ((n - i) % j == 0)
        ans += 2;
    }
    if (round(sqrt(i)) * round(sqrt(i)) == i)
      ans--;
  }

  cout << ans << endl;
}
Problem p02548 (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++)

long long prime_factorize(long long N) {
  long long ansa = 1;
  for (long long a = 2; a * a <= N; ++a) {
    if (N % a != 0)
      continue;
    long long ex = 0; // 指数

    // 割れる限り割り続ける
    while (N % a == 0) {
      ++ex;
      N /= a;
    }

    // その結果を push
    ansa *= (ex + 1);
  }

  // 最後に残った数について
  if (N != 1)
    ansa *= 2;
  return ansa;
}

int main() {
  long long N;
  cin >> N;
  long long M = N;
  int ans;
  int ansans = 0;
  rep(i, N - 1) {
    M -= 1;

    ans = prime_factorize(M);
    ansans += ans;
  }
  cout << ansans << endl;
}

Error: TLE

Fixed submission:

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

long long divisor(long long N) {
  vector<long long> res;
  for (long long i = 1; i * i <= N; ++i) {
    if (N % i == 0) {
      res.push_back(i);
      // 重複しないならば i の相方である N/i も push
      if (N / i != i)
        res.push_back(N / i);
    }
  }
  return res.size();
}
int main() {
  long long N;
  cin >> N;
  long long M = N;
  int ans;
  int ansans = 0;
  rep(i, N - 1) {
    M -= 1;

    ans = divisor(M);
    ansans += ans;
  }
  cout << ansans << endl;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <iostream>
#include <vector>

using namespace std;

int Function(int n) {
  int ans = 0;
  int tmp = 0;
  for (int i = 1; i <= sqrt(n); ++i) {
    if (i * i == n) {
      tmp = 1;
      break;
    }
    if (n % i == 0)
      ans++;
  }
  return ans * 2 + tmp;
}

int main() {

  int N;
  cin >> N;

  int ans = 0;
  for (int i = 1; i < N; ++i) {
    int buf = N - i;
    ans += Function(buf);
  }
  cout << ans;

  return 0;
}

Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>
#include <vector>

using namespace std;

int main() {

  int N;
  cin >> N;

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

  cout << ans;

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

#include <bits/stdc++.h>
#include <limits>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
#define fi(i, n) for (ll i = 0; i < n; i++)
#define f(i, a, b) for (ll i = a; i < b; i++)
#define vi vector<int>
#define pb push_back
#define MOD 1000000007

ll digits(ll n) { return floor(log10(double(n))) + 1; }
vector<ll> SieveOfEratosthenes(ll n, ll a) {
  bool prime[n + 1];
  memset(prime, true, sizeof(prime));
  vector<ll> v;
  for (ll p = 2; p * p <= n; p++) {
    if (prime[p] == true) {

      for (ll i = p * p; i <= n; i += p)
        prime[i] = false;
    }
  }

  for (ll p = a; p <= n; p++)
    if (prime[p])
      v.push_back(p);
  return v;
}
void permute(string a, int l, int r) {
  // permutes string
  if (l == r) {
    cout << a << endl;
  } else {
    for (int i = l; i <= r; i++) {
      swap(a[l], a[i]);
      permute(a, l + 1, r);
    }
  }
}
int main() {
  int n;
  cin >> n;
  int ans = 0;
  for (int i = 1; i < n; i++) {
    for (int j = 1; i * j < n; j++) {
      ans++;
    }
  }
  cout << ans;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <limits>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
#define fi(i, n) for (ll i = 0; i < n; i++)
#define f(i, a, b) for (ll i = a; i < b; i++)
#define vi vector<int>
#define pb push_back
#define MOD 1000000007

ll digits(ll n) { return floor(log10(double(n))) + 1; }
vector<ll> SieveOfEratosthenes(ll n, ll a) {
  bool prime[n + 1];
  memset(prime, true, sizeof(prime));
  vector<ll> v;
  for (ll p = 2; p * p <= n; p++) {
    if (prime[p] == true) {

      for (ll i = p * p; i <= n; i += p)
        prime[i] = false;
    }
  }

  for (ll p = a; p <= n; p++)
    if (prime[p])
      v.push_back(p);
  return v;
}
void permute(string a, int l, int r) {
  // permutes string
  if (l == r) {
    cout << a << endl;
  } else {
    for (int i = l; i <= r; i++) {
      swap(a[l], a[i]);
      permute(a, l + 1, r);
    }
  }
}
int main() {
  int n;
  cin >> n;
  int factors[n + 1];
  factors[0] = 0;
  factors[1] = 1;
  for (int i = 2; i <= n; i++) {
    int count = 0;
    for (int j = 1; j <= sqrt(i); j++) {
      if (i % j == 0) {
        if (i / j == j) {
          count++;
        } else
          count += 2;
      }
    }
    factors[i] = count;
  }

  int ans = 0;
  for (int i = 1; i < n; i++) {
    ans += factors[i];
  }
  cout << ans;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  int A;
  int N;
  cin >> N;
  int count = 0;
  for (A = 1; A < N; A++) {
    count += (N - 1) / A;
  }
  cout << count << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int B = 1;
  int C = 1;
  int N;
  cin >> N;
  int count = 0;
  while (B < N) {
    if ((N - C) % B == 0) {
      count++;
      C++;
      B = 1;
    } else
      B++;
  }
  cout << count << endl;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int N;
  cin >> N;
  int ans = 0;
  for (int C = 1; C < N; C++) {
    int k = N - C;
    int Q = sqrt(k);
    if (Q * Q == k)
      ans--;
    for (int A = 1; A <= Q; A++) {
      int d;
      d = k % A;
      if (d == 0) {
        ans = ans + 2;
      }
    }
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  int N;
  cin >> N;
  int ans = 0;
  for (int C = 1; C < N; C++) {
    int k = N - C;
    int Q = sqrt(k);
    for (int A = 1; A <= Q; A++) {
      int d, e;
      d = k % A;
      e = k / A;
      if (d == 0) {
        ans = ans + 2;
        if (e == A) {
          ans--;
        }
      }
    }
  }
  cout << ans << endl;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  long long a;
  cin >> a;
  long long ans = 0, wa = 0;
  int n;
  n = sqrt(a);
  for (long long i = 1; i <= n; i++)
    for (long long j = i; j <= a - 1; j++) {
      if (i * j < a)
        ans++;
      if (i == j && i * j < a)
        wa++;
    }
  cout << ans * 2 - wa;
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int a;
  cin >> a;
  int ans = 0, wa = 0;
  for (int i = 1; i <= (a + 1) / 2; i++)
    for (int j = i; j <= a - 1; j++) {
      if (i * j < a)
        ans++;
      if (i == j && i * j < a)
        wa++;
    }
  cout << ans * 2 - wa;
  return 0;
}
Problem p02548 (C++) — buggy submission, verdict: Runtime Error

/* To Kaise Hain Aaplog*/

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define all(x) (x).begin(), (x).end()

void shuru_krte_hai_bina_kisi_bakchodi_ke() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE
}

const int mod = 1e9 + 7;
const int s = 1e6 + 1;

int32_t main() {

  // shuru_krte_hai_bina_kisi_bakchodi_ke();
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  int div[n + 10] = {0};
  for (int i = 1; i <= n; i++) {
    for (int j = i; j <= n; j += i) {
      div[j]++;
    }
  }
  int ans = 0;
  for (int i = 1; i < n; i++) {
    // deb2(div[n-i],n-i);
    ans += div[n - i];
  }
  cout << ans;
  return 0;
}

Error: 0

Fixed submission:

/* To Kaise Hain Aaplog*/

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define all(x) (x).begin(), (x).end()

void shuru_krte_hai_bina_kisi_bakchodi_ke() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE
}

const int mod = 1e9 + 7;
const int s = 1e6 + 1;
void Sieve(int n, bool isprime[], bool primesquare[], int a[]) {

  for (int i = 2; i <= n; i++)
    isprime[i] = true;

  for (int i = 0; i <= (n * n + 1); i++)
    primesquare[i] = false;

  // 1 is not a prime number
  isprime[1] = false;

  for (int p = 2; p * p <= n; p++) {

    if (isprime[p] == true) {

      for (int i = p * 2; i <= n; i += p)
        isprime[i] = false;
    }
  }

  int j = 0;
  for (int p = 2; p <= n; p++) {
    if (isprime[p]) {

      a[j] = p;

      primesquare[p * p] = true;
      j++;
    }
  }
}

int countdiv(int n) {

  if (n == 1)
    return 1;

  bool isprime[n + 1], primesquare[n * n + 1];

  int a[n];
  Sieve(n, isprime, primesquare, a);

  int answer = 1;

  for (int i = 0;; i++) {

    if (a[i] * a[i] * a[i] > n)
      break;

    int count = 1;
    while (n % a[i] == 0) {
      n = n / a[i];
      count = count + 1;
    }

    answer = answer * count;
  }

  if (isprime[n])
    answer = answer * 2;

  else if (primesquare[n])
    answer = answer * 3;

  else if (n != 1)
    answer = answer * 4;

  return answer;
}

int32_t main() {

  // shuru_krte_hai_bina_kisi_bakchodi_ke();
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  int ans = 0;
  for (int i = 1; i < n; i++) {
    int val = n - i;
    int x = countdiv(val);
    ans += x;
  }
  cout << ans << "\\n";

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

/*  -*- coding: utf-8 -*-
 *
 * c.cc: C - A x B &#43; C
 */

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

/* constant */

const int MAX_N = 1000000;

/* typedef */

/* global variables */

int cs[MAX_N];

/* subroutines */

/* main */

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

  for (int i = 1; i < n; i++)
    for (int j = i; j < n; j += i)
      cs[j]++;

  int sum = 0;
  for (int i = 1; i < n; i++)
    sum += cs[i];

  printf("%d\\n", sum);
  return 0;
}


Error: TLE

Fixed submission:

/*  -*- coding: utf-8 -*-
 *
 * c.cc: C - A x B &#43; C
 */

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

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

  int cnt = 0;
  for (int m = 1; m < n; m++)
    for (int p = 1; p * p <= m; p++)
      if (m % p == 0) {
        int q = m / p;
        cnt += (p != q) ? 2 : 1;
      }

  printf("%d\\n", cnt);
  return 0;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

int main() {
  int n;
  cin >> n;
  long long int ans = 0;
  for (int i = 1; i <= n - 1; i++) {
    int x = n - i, factors = 0;
    for (int j = 1; j <= sqrt(x); j++)
      if (x % j == 0)
        factors++;
    long double sr = sqrt(x);
    if (sr - floor(sr) == 0)
      ans += (factors - 1) * 2 + 1;
    else
      ans += factors * 2;
  }
  cout << ans;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main() {
  int n;
  cin >> n;
  long long int ans = 0;
  for (int i = 1; i <= n - 1; i++) {
    int x = n - i, factors = 0;
    for (int j = 1; j <= x; j++)
      if (x % j == 0)
        factors++;
    ans += factors;
  }
  cout << ans;
  return 0;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define s(x, n) memset(x, n, sizeof(x));
#define pb(x) push_back(x)
#define NIL -1
#define MAXN 11

void solve() {
  int n;
  cin >> n;
  int ans = 0;
  for (int i = 1; i <= n - 1; i++) {
    // cout << ""
    for (int j = 1; j * j <= i; j++) {
      if (i % j == 0) {
        // cout << i << " " << j << "\\n";
        if (i / j == j)
          ans++;
        else
          ans += 2;
      }
    }
    // cout << "i= " << i << " " << ans << "\\n";
  }
  cout << ans << "\\n";
}
int main() {
#ifdef WIN32
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

#ifndef WIN32
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
#endif
  int t;
  t = 1;
  /// cin >> t;
  for (int I = 1; I <= t; I++) {
    solve();
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define s(x, n) memset(x, n, sizeof(x));
#define pb(x) push_back(x)
#define NIL -1
#define MAXN 11

void solve() {
  ll n;
  cin >> n;
  ll ans = 0;
  for (ll i = 1; i <= n - 1; i++) {
    // cout << ""
    for (ll j = 1; j * j <= i; j++) {
      if (i % j == 0) {
        // cout << i << " " << j << "\\n";
        if (i / j == j)
          ans++;
        else
          ans += 2;
      }
    }
    // cout << "i= " << i << " " << ans << "\\n";
  }
  cout << ans << "\\n";
}
int main() {
#ifdef WIN32
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

#ifndef WIN32
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
#endif
  int t;
  t = 1;
  /// cin >> t;
  for (int I = 1; I <= t; I++) {
    solve();
  }
  return 0;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int ans = 0;
  for (int i = 1; i < n; ++i)
    ans += (n - 1) / i;
  cout << ans;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define int long long
#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define re(x) cout << (#x) << " is " << (x) << "\\n";
#define gif(a, b) ((a) / (b) + ((a) % (b) ? 1 : 0))
using namespace std;

int fun(int n) {
  int ans = 0;
  for (int i = 1; i * i <= n; ++i) {
    if (n % i == 0) {
      ans++;
      if (n / i != i)
        ans++;
    }
  }
  return ans;
}
int32_t main() {
  IOS int T = 1;
  // cin >> T;
  for (int t = 0; t < T; ++t) {
    int n;
    cin >> n;
    int ans = 0;
    for (int i = 1; i <= n - 1; ++i)
      ans += fun(i);
    cout << ans;
  }
  return 0;
}
// if not working? go ahead.
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <iostream>

using namespace std;

int main() {
  int n;
  int tupleCount = 0;

  cin >> n;

  for (int i = 1; i < n; i++) {
    tupleCount += (n - 1) / i;
  }

  cout << tupleCount << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <cmath>
#include <cstring>
#include <iostream>

using namespace std;

int divisors[1000001];

int calculateDivisorCount(int n) {
  if (n == 1)
    return 1;

  int original = n;
  int divisor = 2;
  int divisorCount = 1;

  while (n > 1) {
    if (n % divisor == 0) {
      n /= divisor;
      divisors[divisor]++;
    } else
      divisor++;
  }

  for (int i = 2; i <= original; i++) {
    divisorCount *= divisors[i] + 1;
  }

  return divisorCount;
}

int main() {
  int n;
  int tupleCount = 0;

  cin >> n;

  for (int i = 1; i < n; i++) {
    tupleCount += calculateDivisorCount(i);

    memset(divisors, 0, sizeof(divisors));
  }

  cout << tupleCount << endl;

  return 0;
}