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

#include <bits/stdc++.h>
using namespace std;
#define PI (3.14159265358979323846)
#define ld long double
#define int long long
#define MOD 1000000007
#define w(x)                                                                   \\
  int x;                                                                       \\
  cin >> x;                                                                    \\
  while (x--)
#define F first
#define S second
#define PB push_back

const char nl = '\\n';
const int N = 1e6 + 5;

bool vis[N] = {0};
vector<int> sev;

int no_of_fact(int n) {

  int x = 1, o = n;

  for (auto p : sev) {
    int c = 0;

    if (p * p > n)
      break;

    while (n % p == 0) {
      c++;
      n /= p;
    }
    x *= (c + 1);
  }

  if (n > 2)
    x *= 2;

  return x;
}

void solve() {

  int n;
  cin >> n;

  for (int i = 2; i < n; i++) {
    if (!vis[i]) {
      sev.PB(i);
      for (int j = i * i; j < N; j += i) {
        if (j % i == 0)
          vis[j] = 1;
      }
    }
  }

  int ans = 1;
  for (int i = 2; i <= n - 1; i++) {
    if (!vis[i])
      ans += 2;
    else
      ans += no_of_fact(i);
  }

  cout << ans << nl;
}

int32_t main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  solve();
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define PI (3.14159265358979323846)
#define ld long double
#define int long long
#define MOD 1000000007
#define w(x)                                                                   \\
  int x;                                                                       \\
  cin >> x;                                                                    \\
  while (x--)
#define F first
#define S second
#define PB push_back

const char nl = '\\n';
const int N = 1e4 + 5;

void solve() {

  int n;
  cin >> n;

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

  cout << ans << nl;
}

int32_t main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int t = 1;
  // cin >> t;
  while (t--)
    solve();
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cassert>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;

#define read_int(X)                                                            \\
  ll X;                                                                        \\
  scanf("%lld\\n", &X);

#define read_two_int(X, Y)                                                     \\
  ll X, Y;                                                                     \\
  scanf("%lld %lld\\n", &X, &Y);

#define read_three_int(X, Y, Z)                                                \\
  ll X, Y, Z;                                                                  \\
  scanf("%lld %lld %lld\\n", &X, &Y, &Z);

#define read_four_int(X, Y, Z, W)                                              \\
  ll X, Y, Z, W;                                                               \\
  scanf("%lld %lld %lld %lld\\n", &X, &Y, &Z, &W);

int main() {
  ll N;
  scanf("%lld", &N);

  ll ans = 0;
  for (ll i = 1; i < N; i++) {
    ans += N / i;
  }
  for (ll j = 1; j * j <= N; j++) {
    if (N % j == 0) {
      ans--;
      if (N / j != j)
        ans--;
    }
  }
  ans++;

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


Error: TLE

Fixed submission:

#include <algorithm>
#include <cassert>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;

#define read_int(X)                                                            \\
  ll X;                                                                        \\
  scanf("%lld\\n", &X);

#define read_two_int(X, Y)                                                     \\
  ll X, Y;                                                                     \\
  scanf("%lld %lld\\n", &X, &Y);

#define read_three_int(X, Y, Z)                                                \\
  ll X, Y, Z;                                                                  \\
  scanf("%lld %lld %lld\\n", &X, &Y, &Z);

#define read_four_int(X, Y, Z, W)                                              \\
  ll X, Y, Z, W;                                                               \\
  scanf("%lld %lld %lld %lld\\n", &X, &Y, &Z, &W);

int main() {
  ll N;
  scanf("%lld", &N);

  ll ans = 0;
  for (ll i = 1; i < N; i++) {
    for (ll j = 1; j * j <= i; j++) {
      if (i % j == 0) {
        ans++;
        if (i / j != j)
          ans++;
      }
    }
  }

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

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define f(i, x, n) for (int i = x; i < (int)n; ++i)
#define vpii vector<pair<int, int>>
#define vi vector<int>
#define mpii map<pair<int, int>, int>
#define mpivpii map<int, vector<pair<int, int>>>
#define pii pair<int, int>
#define all(x) x.begin(), x.end()
#define sz(x) x.size()
#define mpi map<int, int>
#define vvi vector<vector<int>>
#define vvvi vector<vvi>
ld pie = 3.141592653589;
int mod = 1e9 + 7;

int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, 1, -1};

vi pr;

int fun(int n) {
  int ret = 0;
  for (int i = 1; i * i <= n; ++i) {
    if (n % i == 0) {
      int ano = n / i;
      ret += 1 + (ano != i);
    }
  }
  return ret;
}

void solve() {
  int n;
  cin >> n;
  int fre[1000006] = {0};
  for (int i = 1; i <= 1000000; ++i)
    for (int j = 1; j <= 1000000; ++j) {
      int pro = i * j;
      if (pro > 1000000)
        break;
      fre[pro]++;
    }
  int cnt = 0;
  f(c, 1, n) {
    int r = n - c;
    cnt += fre[r];
  }
  cout << cnt << "\\n";
}

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1; // cin>>t;
  while (t--)
    solve();
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define f(i, x, n) for (int i = x; i < (int)n; ++i)
#define vpii vector<pair<int, int>>
#define vi vector<int>
#define mpii map<pair<int, int>, int>
#define mpivpii map<int, vector<pair<int, int>>>
#define pii pair<int, int>
#define all(x) x.begin(), x.end()
#define sz(x) x.size()
#define mpi map<int, int>
#define vvi vector<vector<int>>
#define vvvi vector<vvi>
ld pie = 3.141592653589;
int mod = 1e9 + 7;

int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, 1, -1};

vi pr;

int fun(int n) {
  int ret = 0;
  for (int i = 1; i * i <= n; ++i) {
    if (n % i == 0) {
      int ano = n / i;
      ret += 1 + (ano != i);
    }
  }
  return ret;
}

void solve() {
  int n;
  cin >> n;
  int cnt = 0;
  f(c, 1, n) {
    int r = n - c;
    cnt += fun(r);
  }
  cout << cnt << "\\n";
}

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1; // cin>>t;
  while (t--)
    solve();
  return 0;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
inline int read(int x) {
  int f = 1, n = 0;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-')
      f = 0;
    c = getchar();
  }
  while (isdigit(c)) {
    n = n * 10 + int(c - '0');
    c = getchar();
  }
  return f * n;
}
signed main(void) {
  int n, ans = 0;
  n = read(n);
  for (int i = 1; i < n; ++i) {
    int ab = n - i;
    for (int j = 1; j <= int(sqrt(ab)); ++j) {
      if (ab % j == 0) {
        if (j == sqrt(ab))
          ++ans;
        else
          ans += 2;
      }
    }
  }
  printf("%d\\n", ans);
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
signed main(void) {
  int n;
  long long ans = 0;
  cin >> n;
  for (int i = 1; i < n; i++) {
    int ab = n - i;
    for (int j = 1; j <= int(sqrt(ab)); j++) {
      if (j == sqrt(ab) && ab % j == 0)
        ans++;
      else if (ab % j == 0)
        ans += 2;
    }
  }
  cout << ans << endl;
  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 cnt = 0;

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

  cout << cnt << endl;
}

Error: TLE

Fixed submission:

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

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

  vector<int> primeVec = {2};

  long long setsCount = 1;

  for (int a = 2; a <= n - 1; ++a) {
    int divisorCount = 1;
    int aRem = a;

    for (int index = 0; index < primeVec.size(); ++index) {
      int primeI = primeVec.at(index);

      int count = 0;

      while (aRem % primeI == 0) {
        aRem /= primeI;
        ++count;
      }

      divisorCount *= (count + 1);

      if (aRem == 1) {
        break;
      }
    }

    if (divisorCount == 1) {
      primeVec.push_back(a);

      ++divisorCount;
    }

    setsCount += divisorCount;
  }

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

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define P pair<ll, ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
constexpr ll mod = 998244353;
constexpr ll INF = (1ll << 60);
constexpr double pi = 3.14159265358979323846;
template <typename T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

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

  ll ans = 0;

  for (ll a = 1; a <= n; a++) {
    if ((n / a) * a != n)
      ans += n / a;
    else
      ans += (n / a - 1);
  }

  cout << ans << "\\n";

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define P pair<ll, ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
constexpr ll mod = 1000000007;
constexpr ll INF = (1ll << 60);
constexpr double pi = 3.14159265358979323846;
template <typename T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

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

int main() {
  ll ans = 0, n;
  cin >> n;

  for (ll c = 1; c <= n - 1; c++) {
    ans += divisor(n - c);
  }

  cout << ans << "\\n";

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

/* https://codeforces.com/contest/1360/problem/H */
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using vs = vector<string>;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vpi = vector<pair<int, int>>;
using vpl = vector<pair<ll, ll>>;
using ld = double;

#define f first
#define s second
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
#define ins insert

const int MAX = INT_MAX;
const int MOD = 998244353;

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 << endl;
  return 0;
}


Error: TLE

Fixed submission:

/* https://codeforces.com/contest/1360/problem/H */
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using vs = vector<string>;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vpi = vector<pair<int, int>>;
using vpl = vector<pair<ll, ll>>;
using ld = double;

#define f first
#define s second
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
#define ins insert

const int MAX = INT_MAX;
const int MOD = 998244353;

int main() {
  int N;
  cin >> N;
  int ans = 0;
  for (int i = 1; i <= N; ++i)
    for (int j = 1; j <= N; ++j)
      for (int k = 1; k <= N; ++k)
        if (j * i + k == N)
          ans++;

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

/*******************************
 * BASMILLAHHIR RAHMANNIR RAHIM *
 * MD SHAHINUR RAHMAN           *
 * DATE: 16/sep/2020            *
 * DEPT. OF CSE                 *
 * LEADING UNIVERSITY, SYLHET   *
 *******************************/
#include <algorithm>
#include <bits/stdc++.h>
#include <math.h>
#include <stdlib.h>
#include <string>
#include <vector>
#define shahin                                                                 \\
  std::ios_base::sync_with_stdio(false);                                       \\
  std::cin.tie(NULL);
#define ll long long
#define pb push_back
#define sz(x) (int)(x).size()
const int nax = 1000 * 1007;
const int mod = 1e9 + 7;

using namespace std;
char wcz[nax];

bool fu(int a, int b) { return (a > b); }
int gcd(int x, int y) { return x ? gcd(y % x, x) : y; }

void fun() {
  ll n, s = 0;
  cin >> n;

  for (int i = 1; i <= n; i++) {
    ll a = (n - 1) / i;
    s += a;
  }

  cout << s << endl;
}
int main() {
  shahin
  /*   int tc,i=1,sum=0,A=0,B=0;
     cin >> tc;
     while(tc--)
     {
     //cout << "Case " << i << ": ";
         fun();
     //i++;
     }*/
  fun();
}

Error: TLE

Fixed submission:

/*******************************
 * BASMILLAHHIR RAHMANNIR RAHIM *
 * MD SHAHINUR RAHMAN           *
 * DATE: 16/sep/2020            *
 * DEPT. OF CSE                 *
 * LEADING UNIVERSITY, SYLHET   *
 *******************************/
#include <algorithm>
#include <bits/stdc++.h>
#include <math.h>
#include <stdlib.h>
#include <string>
#include <vector>
#define shahin                                                                 \\
  std::ios_base::sync_with_stdio(false);                                       \\
  std::cin.tie(NULL);
#define ll long long
#define pb push_back
#define sz(x) (int)(x).size()
const int nax = 1000 * 1007;
const int mod = 1e9 + 7;

using namespace std;
char wcz[nax];

bool fu(int a, int b) { return (a > b); }
int gcd(int x, int y) { return x ? gcd(y % x, x) : y; }

void fun() {
  ll n, s = 0;
  cin >> 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)
          s++;
      }
    }
  }
  cout << s << endl;
}
int main() {
  shahin
  /*   int tc,i=1,sum=0,A=0,B=0;
     cin >> tc;
     while(tc--)
     {
     //cout << "Case " << i << ": ";
         fun();
     //i++;
     }*/
  fun();
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

  for (int a = 1; a <= n - 1; a++) {
    ans += (n - 1) / a;
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

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

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

  for (int c = 1; c < n; c++) {
    int tmp = 0;
    for (int a = 1; a * a <= n - c; a++) {
      if ((n - c) % a == 0) {
        int b = (n - c) / a;
        if (a == b)
          ans++;
        else
          ans += 2;
      }
    }
  }

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

#include <stdio.h>
#include <string.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define rep(i, N) for (int i = 0; i < (int)N; i++)
static inline void PUT(char c) {
  static char buf[1 << 15], *ptr = buf;
  if (ptr == buf + strlen(buf) || c == 0) {
    fwrite(buf, 1, ptr - buf, stdout), ptr = buf;
  }
  *ptr++ = c;
}
static inline int IN(void) {
  int x = 0, f = 0, c = getchar();
  while (c < 48 || c > 57) {
    f ^= c == 45, c = getchar();
  }
  while (c > 47 && c < 58) {
    x = x * 10 + c - 48, c = getchar();
  }
  return f ? -x : x;
}
static inline void OUT(int a) {
  if (a < 0)
    PUT('-'), a = -a;
  int d[40], i = 0;
  do {
    d[i++] = a % 10;
  } while (a /= 10);
  while (i--) {
    PUT(d[i] + 48);
  }
  PUT('\\n');
}
int main() {
  int N = IN(), count = 0;
  rep(i, N - 1) { count += (N - 1) / (i + 1); }
  return OUT(count), 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>
#include <string.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define rep(i, N) for (int i = 0; i < (int)N; i++)
static inline void PUT(char c) {
  static char buf[1 << 15], *ptr = buf;
  if (ptr == buf + strlen(buf) || c == 0) {
    fwrite(buf, 1, ptr - buf, stdout), ptr = buf;
  }
  *ptr++ = c;
}
static inline int IN(void) {
  int x = 0, f = 0, c = getchar();
  while (c < 48 || c > 57) {
    f ^= c == 45, c = getchar();
  }
  while (c > 47 && c < 58) {
    x = x * 10 + c - 48, c = getchar();
  }
  return f ? -x : x;
}
static inline void OUT(int a) {
  if (a < 0)
    PUT('-'), a = -a;
  int d[40], i = 0;
  do {
    d[i++] = a % 10;
  } while (a /= 10);
  while (i--) {
    PUT(d[i] + 48);
  }
  PUT('\\n');
}
int main() {
  int N = IN(), count = 0;
  rep(i, N) rep(j, N) rep(k, N) {
    if ((i + 1) * (j + 1) + k + 1 == N) {
      count++;
    }
  }
  return OUT(count), 0;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define ll long long
#define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define bug cout << "ok" << endl

const ll INF = 1e9 + 5, N = 1e6 + 5, mod = 998244353, M = 1e6 + 5;

ll d[N];

int main() {
  for (ll i = 2; i <= N - 5; i++) {
    if (d[i] > 0)
      continue;
    d[i] = i;
    ll ch = i * 1ll * i;
    if (ch > N - 5)
      continue;
    for (ll j = i * i; j <= N - 5; j += i) {
      if (d[j] > 0)
        continue;
      d[j] = i;
    }
  }
  ll n;
  cin >> n;
  ll ans = 1;
  for (int i = 2; i < n; i++) {
    ll cnt = 1;
    ll x = i;
    while (x > 1) {
      int dv = d[x];
      int um = 1;
      while (x % dv == 0) {
        um++;
        x /= dv;
      }
      cnt *= um;
    }
    ans += (cnt);
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define ll long long
#define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define bug cout << "ok" << endl

const ll INF = 1e9 + 5, N = 1e6 + 5, mod = 998244353, M = 1e6 + 5;

int main() {
  int d[N];
  ll n;
  cin >> n;
  ll ans = 1;
  for (int i = 2; i < n; i++) {
    for (int j = 1; j <= sqrt(i); j++) {
      if (i % j == 0) {
        int dv = i / j;
        if (i / dv == dv)
          ans--;
        ans += 2;
      }
    }
  }
  cout << ans << endl;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#include <iostream>
#define LL long long int
using namespace std;
LL div(LL n) {
  LL count = 0;
  for (LL i = 1; i <= sqrt(n); i++) {
    if (n % i == 0) {
      count++;
      if (n / i != i)
        count++;
    }
  }
  return count;
}
int main() {
  //	ios_base::sync_with_stdio(false);
  //  cin.tie(NULL);
  vector<LL> v;
  v.push_back(0);
  LL n;
  cin >> n;
  LL count = 0;
  n--;
  LL r = sqrt(n);
  for (LL i = 1; i <= r; i++) {
    count += n / i;
  }
  count = count * 2;
  count -= r * r;
  cout << count << "\\n";
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <iostream>
#define LL long long int
using namespace std;
LL div(LL n) {
  LL count = 0;
  for (LL i = 1; i <= sqrt(n); i++) {
    if (n % i == 0) {
      count++;
      if (n / i != i)
        count++;
    }
  }
  return count;
}
int main() {
  //	ios_base::sync_with_stdio(false);
  //  cin.tie(NULL);
  vector<LL> v;
  v.push_back(0);
  for (LL i = 1; i <= 1000000; i++) {
    LL c = div(i - 1);
    v.push_back(v[i - 1] + c);
  }
  LL n;
  cin >> n;
  cout << v[n] << "\\n";
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

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

  int N;
  cin >> N;
  int cnt = 0;
  for (int a = 1; a < N; a++) {
    cnt += (N - 1) / a;
  }
  cout << cnt << "\\n";
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int isqrt(int n) {
  int i = 1;
  while (i * i < n) {
    i <<= 1;
  }
  int res = 0;
  while (i > 0) {
    if ((res + i) * (res + i) <= n) {
      res += i;
    }
    i >>= 1;
  }
  return res;
}

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

  int N;
  cin >> N;
  int cnt = 0;
  for (int c = 1; c < N; c++) {
    int ab = N - c;
    for (int a = 1; a <= isqrt(ab); a++) {
      if (ab % a == 0) {
        if (a * a == ab) {
          cnt++;
        } else {
          cnt += 2;
        }
      }
    }
  }
  cout << cnt << "\\n";
  return 0;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#include <iostream>

using namespace std;

int main() {
#ifdef LOCAL_EXEC
#else
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
#endif // LOCAL_EXEC
  long long int n, i, j, k, x = 0, y;
  cin >> n;
  for (i = 1; i <= n - 1; i++) {
    x += (n - 1) / i;
  }
  cout << x;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <iostream>

using namespace std;

int main() {
#ifdef LOCAL_EXEC
#else
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
#endif // LOCAL_EXEC
  int n, i, j, k, x, y, z;
  cin >> n;
  int dp[n + 1];
  dp[0] = 0;
  dp[1] = 0;
  for (i = 2; i <= n; i++) {
    dp[i] = dp[i - 1];
    x = 0;
    for (j = 1; j * j <= i - 1; j++) {
      if ((i - 1) % j == 0) {
        x += 1;
        if (j != (i - 1) / j)
          x += 1;
      }
    }
    dp[i] += x;
  }
  cout << dp[n];
  return 0;
}