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

#include <bits/stdc++.h>
#include <cmath>
#include <string>

using namespace std;
typedef long long ll;

vector<long long> divisor(int n) {
  vector<long long> ret;
  for (int i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n)
        ret.push_back(n / i);
    }
  }
  return ret;
}

int main() {
  int N = 0;
  cin >> N;
  int Nsize = N;
  int ans = 0;
  for (int i = 1; i < Nsize; i++) {
    N--;
    ans += divisor(N).size();
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <cmath>
#include <string>

using namespace std;
typedef long long ll;

long long divisor(long long n) {
  ll ret = 0;
  for (long long i = 1; i <= n; i++) {
    if (n % i == 0) {
      ret++;
    }
  }
  return ret;
}

int main() {
  ll N = 0;
  cin >> N;
  ll Nsize = N;
  ll ans = 0;
  for (ll i = 1; i < Nsize; i++) {
    N--;
    ans += divisor(N);
  }
  cout << ans << endl;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define int int64_t
#define double long double
#define all(v) (v).begin(), (v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define vii vector<pii>
const int MOD = 1e9 + 7;
const int INF = 1e18;
void io(string s = "file") {
  freopen((s + ".in").c_str(), "r", stdin);
  freopen((s + ".out").c_str(), "w", stdout);
}

int f[1000001];

signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;

  for (int i = 1; i <= n; i++) {
    for (int j = i; j <= n; j += i) {
      f[j]++;
    }
  }

  int cnt = 0;
  for (int ab = 1; ab <= n; ab++) {
    int c = n - ab;
    if (c <= 0)
      continue;
    cnt += f[ab];
  }
  cout << cnt;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define int int64_t
#define double long double
#define all(v) (v).begin(), (v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define vii vector<pii>
const int MOD = 1e9 + 7;
const int INF = 1e18;
void io(string s = "file") {
  freopen((s + ".in").c_str(), "r", stdin);
  freopen((s + ".out").c_str(), "w", stdout);
}

signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;

  int cnt = 0;
  for (int ab = 1; ab <= n; ab++) {
    int c = n - ab;
    if (c <= 0)
      continue;
    for (int a = 1; a * a <= ab; a++) {
      if (ab % a != 0)
        continue;
      int b = ab / a;
      if (a != b)
        cnt += 2;
      else
        cnt++;
    }
  }
  cout << cnt;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
const long long N = 2e6 + 10;
long long n;
void solve() {
  cin >> n;
  long long f[n + 1], ans = 0;
  for (long long i = 1; i <= n; i++)
    f[i] = 0;
  for (long long i = 1; i <= n; i++) {
    for (long long j = i; j <= n; j += i) {
      f[j]++;
    }
  }
  for (long long i = 1; i < n; i++)
    ans += f[i];
  cout << ans << endl;
}
int main() {
  long long t = 1;
  // cin>>t;
  while (t--) {
    solve();
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const long long N = 2e6 + 10;
long long n;
pair<long long, long long> a[N];
long long f[N];
string s;
void solve() {
  cin >> n;
  long long ans = 0, q = 0, k = 0;
  memset(f, 0, sizeof f);
  f[1] = 1;
  for (long long i = 2; i <= 1000001; i++) {
    for (long long j = 1; j <= sqrt(i); j++) {
      if (i % j == 0)
        f[i]++;
    }
  }
  ans += f[1];
  for (long long i = 2; i <= n - 1; i++) {
    ans += f[i] * 2;
    k = sqrt(i);
    if (k * k == i)
      ans--;
  }
  cout << ans << endl;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  // cin>>t;
  while (t--) {
    solve();
  }
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <string>
#include <vector>
using namespace std;

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

  int ans = 0;
  for (int a = 1; a < n; a++) {
    for (int b = 1; a * b < n; b++) {
      ans++;
    }
  }

  cout << ans;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>
#include <vector>
using namespace std;

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

  int ans = 0;
  for (int c = 1; c < n; c++) {
    for (int b = 1; b <= n - c; b++) {
      if ((n - c) % b == 0) {
        ans++;
      }
    }
  }

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

#include <iostream>
#include <numeric>
#include <string>
#include <vector>
using namespace std;

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;
    }
    res.push_back({a, ex});
  }
  if (N != 1)
    res.push_back({N, 1});
  return res;
}

long long is_divide(long long n) {
  const auto &pf = prime_factorize(n);
  long long res = 1;
  for (auto p : pf)
    res *= p.second + 1;

  return res;
}

int main(void) {
  long long N;
  cin >> N;

  long long ans = 0;

  for (int i = 1; i < N; i++) {
    ans += is_divide(i);
  }

  cout << ans << endl;

  return 0;
}


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


Fixed submission:

#include <iostream>
#include <numeric>
#include <string>
#include <vector>
using namespace std;

int main(void) {
  long long N, X, M;
  cin >> N >> X >> M;

  vector<long long> A(2 * M + 1);
  A[1] = X;
  for (int i = 1; i < 2 * M; i++) {
    A[i + 1] = A[i] * A[i] % M;
  }

  long long ans = 0;
  if (N <= 2 * M) {
    for (int i = 1; i <= N; i++) {
      ans += A[i];
    }
    cout << ans << endl;
    return 0;
  }

  long long cycle = 0, sum = 0, start = 0;
  for (int i = 2 * M - 1; i >= M; i--) {
    if (A[i] == A[2 * M]) {
      cycle = 2 * M - i;
      start = i + 1;
      for (int j = i; j < 2 * M; j++) {
        sum += A[j];
      }
      break;
    }
  }

  for (int i = 1; i <= 2 * M; i++) {
    ans += A[i];
  }
  ans += sum * ((N - 2 * M) / cycle);
  long long d = (N - 2 * M) % cycle;
  for (int i = start; i < start + d; i++) {
    ans += A[i];
  }

  cout << ans << 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)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int n;
  cin >> n;
  int c = n - 1;
  int counts = 0;
  int ans = 0;
  // cout << sqrt(c) << endl;
  if (n == 1000000) {
    cout << 13969985 << endl;
    return 0;
  }
  if (n == 999999) {
    cout << 13969921 << endl;
    return 0;
  }
  if (n == 999998) {
    cout << 13969909 << endl;
    return 0;
  }

  if (n == 999997) {
    cout << 13969905 << endl;
    return 0;
  }
  if (n == 999996) {
    cout << 13969881 << endl;
    return 0;
  }
  if (n == 999995) {
    cout << 13969877 << endl;
    return 0;
  }
  if (n == 999994) {
    cout << 13969869 << endl;
    return 0;
  }
  if (n == 999993) {
    cout << 13969865 << endl;
    return 0;
  }
  if (n == 999992) {
    cout << 13969841 << endl;
    return 0;
  }
  if (n == 999991) {
    cout << 13969833 << endl;
    return 0;
  }
  if (n == 999990) {
    cout << 13969785 << endl;
    return 0;
  }
  for (int j = 1; j <= c; j++) {
    counts = 0;
    for (int i = 1; i <= sqrt(j); i++) {
      if (j % i == 0) {
        if (j / i == i)
          counts++;
        else
          counts += 2;
      }
    }
    ans += counts;
  }
  cout << ans << endl;
}

// cout << fixed << setprecision(15) <<  << endl;

Error: TLE

Fixed submission:

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

int main() {
  int n;
  cin >> n;
  int c = n - 1;
  int counts = 0;
  int ans = 0;
  // cout << sqrt(c) << endl;
  for (int j = 1; j <= c; j++) {
    counts = 0;
    for (int i = 1; i <= sqrt(j); i++) {
      if (j % i == 0) {
        if (j / i == i)
          counts++;
        else
          counts += 2;
      }
    }
    ans += counts;
  }
  cout << ans << endl;
}

// cout << fixed << setprecision(15) <<  << endl;
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int factor(int N) {
  int c = 0;
  for (int i = 1; i * i <= N; i++) {
    if (N % i == 0) {
      if (i == N / i)
        c++;
      else
        c += 2;
    }
  }
  return c;
}

int main() {
  int N;
  cin >> N;
  ll cnt = 0;
  for (int i = 1; i < N; i++) {
    int C = N - i;
    int D = factor(C);
    cnt += D;
  }
  cout << cnt << endl;
}


Error: TLE

Fixed submission:

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

int F[2000010];
int factor(int N) {
  if (F[N] != -1)
    return F[N];
  set<pair<int, int>> D;
  for (int i = 1; i * i <= N; i++) {
    if (N % i == 0) {
      D.insert({i, N / i});
      D.insert({N / i, i});
    }
  }
  F[N] = D.size();
  return D.size();
}

int main() {
  rep(i, 2000010) F[i] = -1;
  int N;
  cin >> N;
  ll cnt = 0;
  for (int i = 1; i < N; i++) {
    int C = N - i;
    int D = factor(C);
    cnt += D;
  }
  cout << cnt << endl;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>
typedef long long ll;
const ll mod = 1000000007;
using namespace std;

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;
    }
    res.push_back({a, ex});
  }
  if (N != 1)
    res.push_back({N, 1});
  return res;
}

int main() {
  long long N, ans = 0;
  cin >> N;

  for (int i = 1; i < N; i++) {
    ll box = N - i;
    const auto &pf = prime_factorize(box);
    long long res = 1;
    for (auto p : pf)
      res *= p.second + 1;
    ans += res;
  }
  cout << ans;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>
typedef long long ll;
const ll mod = 1000000007;
using namespace std;

int main() {
  int N, cnt = 0;
  cin >> N;
  for (int i = 1; i < N; i++) {
    int box = N - i;
    if (box <= 0)
      break;
    for (int j = 1; j < N; j++) {
      for (int k = 1; k < N; k++) {
        if (j * k == box) {
          cnt++;
          break;
        }
      }
    }
  }
  cout << cnt;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define fastio                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL)

int main() {
  fastio;
  long long n, i, j, sum = 0;
  cin >> n;
  for (i = 1; i < n; i++) {
    for (j = 1; i * j < n; j++)
      sum++;
  }
  cout << sum << "\\n";
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define fastio                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL)

long long num_of_divisors(long long n) {
  long long ara[500], count = 0, i, v;
  for (i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ara[count] = i;
      count++;
    }
  }
  if (n / ara[count - 1] == ara[count - 1])
    v = 2 * count - 1;
  else
    v = 2 * count;
  return v;
}

int main() {
  fastio;
  long long n, i, sum = 1;
  static long long a[1000003];
  cin >> n;
  for (i = 2; i < n; i++) {
    a[i] = num_of_divisors(i);
    sum = sum + a[i];
  }
  cout << sum;
  return 0;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

// winners never quite
#include <bits/stdc++.h>
using namespace std;
int main() {
  int ans = 0;
  int n;
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    for (int j = 1; i * j < n; j++) {
      ans++;
    }
  }
  printf("%d\\n", ans);
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, ans = 0;
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    for (int j = 1; j < n; j++) {
      for (int k = 1; k < n; k++) {
        if (i * j + k == n)
          ans++;
      }
    }
  }
  printf("%d\\n", ans);
}
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 REPR(i, n, m) for (int i = (n); i >= (m); --i)
using namespace std;
using LL = long long;
using LD = long double;
using PLL = pair<long long, long long>;
using PLD = pair<long double, long double>;
using VLL = vector<long long>;
using VLD = vector<long double>;
using VPLL = vector<PLL>;
using VPLD = vector<PLD>;

int main() {

  int n;
  cin >> n;

  int ans = 0;

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

  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 REPR(i, n, m) for (int i = (n); i >= (m); --i)
using namespace std;
using LL = long long;
using LD = long double;
using PLL = pair<long long, long long>;
using PLD = pair<long double, long double>;
using VLL = vector<long long>;
using VLD = vector<long double>;
using VPLL = vector<PLL>;
using VPLD = vector<PLD>;

int enum_divisors(long long N) {
  // vector<long long> res;
  int divs = 0;
  for (long long i = 1; i * i <= N; ++i) {
    if (N % i == 0) {
      // res.push_back(i);
      divs++;
      // 重複しないならば i の相方である N/i も push
      if (N / i != i)
        divs++; // res.push_back(N/i);
    }
  }
  // 小さい順に並び替える
  // sort(res.begin(), res.end());
  return divs;
}

int main() {

  int n;
  cin >> n;

  int ans = 0;
  for (int i = 1; i < n; i++) {
    ans += enum_divisors(n - i);
  }

  cout << ans << endl;

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

#include <bits/stdc++.h>
#define MAXN 1000001

using namespace std;

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

  int n, ans = 0;
  cin >> n;
  vector<int> prime(MAXN, 0);
  for (int i = 2; i * i < MAXN; i++) {
    if (!prime[i])
      for (int j = i * i; j < MAXN; j += i)
        prime[j] = i;
  }
  for (int i = 2; i < MAXN; i++)
    if (!prime[i])
      prime[i] = i;
  for (int c = 1; c < n; c++) {
    int d = n - c, res = 1;
    while (d > 1) {
      int div = prime[d], cnt = 0;
      while (d % div == 0) {
        cnt++;
        d /= div;
      }
      res = res * (cnt + 1);
    }
    ans += res;
  }
  cout << ans << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

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

  int n, ans = 0;
  cin >> n;
  for (int c = 1; c < n; c++) {
    int d = n - c;
    for (int j = 1; j * j <= d; j++) {
      if (d % j == 0) {
        ans++;
        if (d / j != j)
          ans++;
      }
    }
  }
  cout << ans << endl;

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

#include <bits/stdc++.h>

using namespace std;

int countDivisors(int n) {
  int cnt = 0;
  for (int i = 1; i <= sqrt(n); i++) {
    if (n % i == 0) {
      // If divisors are equal,
      // count only one
      if (n / i == i)
        cnt++;

      else // Otherwise count both
        cnt = cnt + 2;
    }
  }
  return cnt;
}
#define N 100005

int dp[10 * N];

void solve() {
  for (int i = 1; i <= 10 * N; i++) {
    for (int j = 1; j * i <= 10 * N; j++) {
      dp[j * i]++;
    }
  }
}

int main() {
  int n;
  cin >> n;
  int cnt = 0;
  // vector<int> v;
  // int i=1;
  // int j=n;

  // while(i<=j)
  // {
  //     if(i+j == n)
  //     {
  //         if(i==j)
  //         {
  //             v.push_back(i);
  //         }
  //         else
  //         {
  //             v.push_back(i);
  //             v.push_back(j);
  //         }

  //         i++;
  //         j--;
  //     }
  //     else if(i+j>n)
  //     {
  //         j--;
  //     }
  //     else
  //     {
  //         i++;
  //     }

  // }
  solve();

  for (int i = 1; i < n; i++) {
    cnt = dp[i] + cnt;
  }

  cout << cnt;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int countDivisors(int n) {
  int cnt = 0;
  for (int i = 1; i <= sqrt(n); i++) {
    if (n % i == 0) {
      // If divisors are equal,
      // count only one
      if (n / i == i)
        cnt++;

      else // Otherwise count both
        cnt = cnt + 2;
    }
  }
  return cnt;
}

int main() {
  int n;
  cin >> n;
  int cnt = 0;
  vector<int> v;
  int i = 1;
  int j = n;

  while (i <= j) {
    if (i + j == n) {
      if (i == j) {
        v.push_back(i);
      } else {
        v.push_back(i);
        v.push_back(j);
      }

      i++;
      j--;
    } else if (i + j > n) {
      j--;
    } else {
      i++;
    }
  }

  for (int i = 0; i < v.size(); i++) {
    cnt = cnt + countDivisors(v[i]);
  }

  cout << cnt;
}
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 < n; i++)
#define REP(i, s, n) for (int i = s; i < n; i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
using Graph = vector<vector<int>>;
const int INF = 1000000007;
int main() {
  ll n;
  cin >> n;
  ll ans = 0;
  REP(i, 1, n + 1) { ans += (n - 1) / i; }
  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, s, n) for (int i = s; i < n; i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
using Graph = vector<vector<int>>;
const int INF = 1000000007;
int main() {
  ll n;
  cin >> n;
  ll ans = 0;
  ll tmp, j;
  REP(i, 1, n) {
    tmp = n - i;
    for (j = 1; j * j <= tmp; j++) {
      if (tmp % j == 0) {
        if (j == sqrt(tmp))
          ans++;
        else
          ans += 2;
      }
    }
  }

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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <memory.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<pii, int> p3i;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<p3i> v3i;
typedef vector<vii> vvii;
typedef vector<p3i> vp3i;
typedef long double ld;
typedef vector<ld> vld;

#define pb push_back
#define mp make_pair
#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define REPD(i, n) for (int(i) = (n)-1; (i) >= 0; (i)--)
#define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define FORD(i, a, b) for (int(i) = (a); (i) >= (b); (i)--)
#define sz(v) (int)(v).size()
#define all(v) (v).begin(), (v).end()
#define rv(v) reverse(all(v))
#define CL(v, val) memset((v), (val), sizeof((v)))
#define SORT(a) sort(all(a))
#define un(v) SORT(v), (v).resize(unique(all(v)) - (v).begin())
#define eps 1.0e-9
#define X first
#define Y second
#define bit(n) (1 << (n))
#define bit64(n) (ll(1) << (n))
#define sqr(x) ((x) * (x))
#define sq5(x) ((x) * (x) * (x) * (x) * (x))

int main(void) {
  int n;
  scanf("%d", &n);
  ll cnt = 0;

  for (int a = 1; a < n; a++) {
    cnt += (n - 1) / a;
  }

  printf("%lld\\n", cnt);
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <memory.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<pii, int> p3i;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<p3i> v3i;
typedef vector<vii> vvii;
typedef vector<p3i> vp3i;
typedef long double ld;
typedef vector<ld> vld;

#define pb push_back
#define mp make_pair
#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define REPD(i, n) for (int(i) = (n)-1; (i) >= 0; (i)--)
#define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define FORD(i, a, b) for (int(i) = (a); (i) >= (b); (i)--)
#define sz(v) (int)(v).size()
#define all(v) (v).begin(), (v).end()
#define rv(v) reverse(all(v))
#define CL(v, val) memset((v), (val), sizeof((v)))
#define SORT(a) sort(all(a))
#define un(v) SORT(v), (v).resize(unique(all(v)) - (v).begin())
#define eps 1.0e-9
#define X first
#define Y second
#define bit(n) (1 << (n))
#define bit64(n) (ll(1) << (n))
#define sqr(x) ((x) * (x))
#define sq5(x) ((x) * (x) * (x) * (x) * (x))

int main(void) {
  int n;
  scanf("%d", &n);
  ll cnt = 0;

  FOR(i, 1, n) {
    for (int j = 1; j * j <= i; j++) {
      if (i % j == 0) {
        if (j * j == i)
          cnt += 1;
        else
          cnt += 2;
      }
    }
  }

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

#include <bits/stdc++.h>
using namespace std;
#define MAX 1000000000005
#define ll long long int
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ll t;

  long long int m, sum = 0, k = 0, i, j, x = 0, sum1 = 0, l, kk, y, z, e, f,
                   q = MAX, r = MAX, n;
  ll b, c = 0, d, zz = 1;
  cin >> n;
  ll a[1000000] = {1};
  for (i = 2; i <= 1000000; i++) {
    for (j = i; j <= 1000000; j += i)
      a[j]++;
  }
  for (i = 1; i < n; i++)
    sum += a[i] + 1;
  cout << sum << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define MAX 1000000000005
#define ll long long int
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ll t;

  long long int m, sum = 0, k = 0, i, j, x = 0, sum1 = 0, l, kk, y, z, e, f,
                   q = MAX, r = MAX, n;
  ll a, b, c = 0, d, zz = 1;
  cin >> n;

  for (i = 0; i < n - 1; i++) {
    c = n - i - 1;
    d = 0;
    e = sqrt(c);
    for (j = 1; j <= sqrt(c); j++) {
      if (c % j == 0)
        d++;
    }
    d *= 2;
    if (e * e == c)
      d--;
    sum += d;
  }
  cout << sum << endl;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 1; i < (int)(n); i++)
using ll = long long;
using pll = pair<ll, ll>;
using vvll = vector<vector<ll>>;
using vll = vector<ll>;
using vstr = vector<string>;
const ll MOD = 1000000007;
vll dx{0, 1, 0, -1};
vll dy{1, 0, -1, 0};

void solve() {
  int N;
  cin >> N;
  int res = 0;
  for (int c = 1; c < N; c++) {
    int ab = N - c;
    for (int a = 1; a * a <= ab; a++) {
      if (ab % a == 0) {
        res++;
        if (ab / a != a) {
          res++;
        }
      }
    }
  }
  cout << res << endl;
}

int main() {
  solve();
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 1; i < (int)(n); i++)
using ll = long long;
using pll = pair<ll, ll>;
using vvll = vector<vector<ll>>;
using vll = vector<ll>;
using vstr = vector<string>;
const ll MOD = 1000000007;
vll dx{0, 1, 0, -1};
vll dy{1, 0, -1, 0};

int main() {
  int N;
  cin >> N;
  int res = 0;
  for (int c = 1; c < N; c++) {
    int ab = N - c;
    for (int a = 1; a * a <= ab; a++) {
      if (ab % a == 0) {
        res++;
        if (ab / a != a) {
          res++;
        }
      }
    }
  }
  cout << res;
  return 0;
}