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

#include <iostream>
using namespace std;

int main() {
  long long ans = 0;
  int x;
  cin >> x;
  for (int i = 1; i < x; i++) {
    if (x % i == 0) {
      ans = ans + (x / i) - 1;
    } else {
      ans = ans + (x / i);
    }
  }

  cout << ans;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
typedef long long ll;

ll nijo(ll x) {
  int a;
  while (a * a < x) {
    a++;
  }
  if (a * a != x) {
    a--;
  }
  return a;
}

ll yakusu(ll x) {
  ll cou = 0;
  ll nt = 0;

  ll a = nijo(x);
  for (ll i = 1; i < a + 1; i++) {
    if (x % i == 0) {
      cou++;
      //      cout << i << "\\n";
    }
  }
  if (nijo(x) * nijo(x) == x) {
    nt = nt + cou * 2 - 1;
  } else {
    nt = nt + cou * 2;
  }
  return nt;
}

int main() {
  int X;
  ll ans = 0;
  cin >> X;
  for (ll c = 1; c < X - 1; c++) {
    ans += yakusu(X - c);
  }
  cout << ans + 1;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;

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

  for (long A = 1; A < N; A++) {
    c += N / A;
    if ((N % A) == 0)
      c--;
  }
  cout << c << endl;
  return (0);
}


Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>

using namespace std;

int main() {
  long N;
  long A, B, C;
  int ab = 0;
  int nab = 0;
  cin >> N;

  for (A = 1; A < N; A++) {
    for (B = A; B < N; B++) {
      if (A * B < N) {
        if (A == B) {
          ab++;
        } else {
          nab++;
        }
      }
    }
  }
  cout << nab * 2 + ab << endl;
  return (0);
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int N;
  cin >> N;
  long long count = 0;
  // iはAに相当
  for (int i = 1; i <= N - 1; i++) {
    count += (N - 1) / i;
  }
  cout << count << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  int N;
  cin >> N;
  long long count = 0;
  vector<int> res;

  int seki;

  for (int i = 1; i <= N - 1; i++) {
    seki = N - i;
    vector<int> res;
    for (long long i = 1; i * i <= seki; ++i) {
      if (seki % i == 0) {
        res.push_back(i);
        // 重複しないならば i の相方である N/i も push
        if (seki / i != i)
          res.push_back(seki / i);
      }
    }

    for (int j = 0; j < res.size(); j++) {
      if (seki % res[j] == 0)
        count++;
    }
  }
  cout << count << endl;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

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

Error: TLE

Fixed submission:

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

long long enum_divisors(long long N) {
  long long ans;
  vector<long long> res;
  for (long long i = 1; i * i <= N; ++i) {
    if (N % i == 0) {
      res.push_back(i);
      if (N / i != i)
        res.push_back(N / i);
    }
  }
  return res.size();
}

int main() {
  long long n;
  cin >> n;
  long long ans = 0;
  for (long long c = 1LL; c < n; c++) {
    long long ab = n - c;
    ans += enum_divisors(ab);
  }
  cout << ans << endl;
}
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 all(v) v.begin(), v.end()
using namespace std;
using ll = long long;

template <typename T> struct PrimeFact {
  vector<T> spf;
  PrimeFact(T N) { init(N); }
  void init(T N) { // 前処理。spf を求める
    spf.assign(N + 1, 0);
    for (T i = 0; i <= N; i++)
      spf[i] = i;
    for (T i = 2; i * i <= N; i++) {
      if (spf[i] == i) {
        for (T j = i * i; j <= N; j += i) {
          if (spf[j] == j) {
            spf[j] = i;
          }
        }
      }
    }
  }
  map<T, T> get(T n) { // nの素因数分解を求める
    map<T, T> m;
    while (n != 1) {
      m[spf[n]]++;
      n /= spf[n];
    }
    return m;
  }
};

int main() {
  ll n;
  cin >> n;
  ll ans = 0;
  PrimeFact<ll> pf(n);

  for (int c = 1; c < n; c++) {
    ll now = n - c;
    ll tmp = 1;
    for (auto t : pf.get(now)) {
      tmp *= t.second + 1;
    }
    ans += tmp;
  }
  cout << ans << endl;
  return 0;
}
/*
g++ -std=c++17 -Wall -Wextra -g -O0 -fsanitize=undefined,address main.cpp && oj
t
*/

Error: TLE

Fixed submission:

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

int main() {
  ll n;
  cin >> n;
  ll ans = 0;
  for (int c = 1; c < n; c++) {
    ll now = n - c;
    ll tmp = 0;
    int k;
    for (k = 1; k * k < now; k++) {
      if (now % k == 0)
        tmp++;
    }
    tmp *= 2;
    if (k * k == now)
      tmp++;
    ans += tmp;
  }
  cout << ans << endl;
  return 0;
}
/*
g++ -std=c++17 -Wall -Wextra -g -O0 -fsanitize=undefined,address main.cpp && oj
t
*/
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ordered_set                                                            \\
  tree<int, null_type, less<int>, rb_tree_tag,                                 \\
       tree_order_statistics_node_update>
#define ll long long
#define FASTIO                                                                 \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define inf 1e9
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define mod 1000000007
#define pb push_back
#define all(s) s.begin(), s.end()
#define pie 3.14159265358979323846
#define fr(i, a, b) for (ll i = a; i < b; i++)
#define frr(i, a, b) for (ll i = b - 1; i >= a; i--)
#define gcd __gcd
#define con continue
#define pii pair<ll, ll>
inline ll fac(ll n) {
  ll res = 0;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      if (n / i != i)
        res += 2;
      else
        res += 1;
    }
  }
  return res;
}
signed main() {
  FASTIO;
  ll tt = 1;
  // cin>>tt;
  while (tt--) {
    ll n, ans = 0;
    cin >> n;
    for (ll i = 1; i < n; i++) {
      ans += (n - 1) / i;
    }
    cout << ans << "\\n";
  }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ordered_set                                                            \\
  tree<int, null_type, less<int>, rb_tree_tag,                                 \\
       tree_order_statistics_node_update>
#define ll long long
#define FASTIO                                                                 \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define inf 1e9
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define mod 1000000007
#define pb push_back
#define all(s) s.begin(), s.end()
#define pie 3.14159265358979323846
#define fr(i, a, b) for (ll i = a; i < b; i++)
#define frr(i, a, b) for (ll i = b - 1; i >= a; i--)
#define gcd __gcd
#define con continue
#define pii pair<ll, ll>
inline ll fac(ll n) {
  ll res = 0;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      if (n / i != i)
        res += 2;
      else
        res += 1;
    }
  }
  return res;
}
signed main() {
  ll tt = 1;
  // cin>>tt;
  while (tt--) {
    ll n, ans = 0;
    cin >> n;
    for (ll i = 1; i < n; i++) {
      ans += fac(n - i);
    }
    cout << ans << "\\n";
  }
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1000010;
unordered_map<int, int> m;

int main() {
  int n;
  cin >> n;
  bool st[n + 1];
  int ans = 0;
  int x = (int)sqrt(n);
  for (int i = 2; i <= x; i++) {
    for (int j = 2; i * j <= n; j++) {
      if (j > x)
        m[i * j] += 2;
      else
        m[i * j] += 1;
    }
  }
  for (int i = 2; i < n; i++) {
    ans += m[i];
  }
  cout << ans + n * 2 - 3 << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1000010;
int st[N];
unordered_map<int, int> m;

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

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

#include <bits/stdc++.h>

#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

using namespace std;

typedef long long ll;

int main() {
  int n;
  cin >> n;
  vector<int> lp(n, int(1e9));
  vector<bool> prime(n, true);
  ll ans = 1;
  for (int num = 2; num < n; ++num) {
    if (prime[num]) {
      lp[num] = num;
      for (int j = num; j < n; j += num) {
        prime[j] = false;
        lp[j] = min(lp[j], num);
      }
    }
  }
  for (int num = 2; num < n; ++num) {
    ll mul = 1;
    int number = num;
    int lastmul = 0;
    int previous = -1;
    while (number != 1) {
      if (lp[number] == previous) {
        ++lastmul;
      } else {
        mul *= (lastmul + 1);
        lastmul = 1;
        previous = lp[number];
      }
      number /= lp[number];
    }
    mul *= (lastmul + 1);
    ans += mul;
  }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

using namespace std;

typedef long long ll;

int main() {
  int n;
  cin >> n;
  vector<int> counter(n + 1);
  ll ans = 0;
  for (int num = 1; num < n; ++num) {
    ll cnt = 0;
    for (int div = 1; div * 1ll * div <= num; ++div) {
      if (num % div == 0) {
        if (num / div != div)
          ans += 2;
        else
          ++ans;
      }
    }
  }
  cout << ans << "\\n";
  return 0;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

#define rep(i, n) for (int i = 0; i < n; i++)
#include <bits/stdc++.h>
#include <vector>
typedef long long ll;
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() {
  ll n;
  cin >> n;
  unsigned long long ans = 0;
  // vector <int> res;
  for (ll i = 1; i < n; i++) {

    const auto &pf = prime_factorize(i);
    long long res = 1;
    for (auto p : pf)
      res *= p.second + 1;
    ans += res;
    // cout << ans << endl;
  }

  /*for (int i = 0; i < (int)res.size(); ++i) //cout << res[i] << " ";
    cout << endl;*/

  cout << ans << endl;
}


Error: TLE

Fixed submission:

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

vector<long long> enum_divisors(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);
    }
  }
  // 小さい順に並び替える
  sort(res.begin(), res.end());
  return res;
}

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

  for (int i = 1; i < n; i++) {
    const auto &res = enum_divisors(i);
    ans += (int)res.size();
  }

  /*for (int i = 0; i < res.size(); ++i) cout << res[i] << " ";
    cout << endl;
}
*/
  cout << ans << endl;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
using pp = pair<int, int>;
using ll = long long;

int main() {
  int N, count = 0;
  cin >> N;
  int n;
  for (int c = 1; c < N; c++) {
    n = N;
    n -= c;
    int m, del = 0;
    for (int i = 1; i <= n + 1; i++) {
      if (i * i > n) {
        m = i - 1;
        if (m * m == n) {
          del = 1;
        }
        break;
      }
    }
    count -= del;
    if (n % 2 == 0) {
      for (int a = 1; a <= m; a++) {
        if (n % a == 0) {
          count += 2;
        }
      }
    } else {
      for (int a = 1; a <= m; a += 2) {
        if (n % a == 0) {
          count += 2;
        }
      }
    }
  }
  cout << count << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using pp = pair<int, int>;
using ll = long long;

int main() {
  int N, count = 0;
  cin >> N;
  int n;
  for (int c = 1; c < N; c++) {
    n = N;
    n -= c;
    int m, del = 0;
    for (int i = 1; i <= n + 1; i++) {
      if (i * i > n) {
        m = i - 1;
        if (m * m == n) {
          del = 1;
        }
        break;
      }
    }
    count -= del;
    for (int a = 1; a <= m; a++) {
      if (n % a == 0) {
        count += 2;
      }
    }
  }
  cout << count << 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 < (n); ++i)

int main() {
  int N;
  int sumdiv = 0;
  cin >> N;
  for (int j = 1; j < N; ++j) {
    int divisors_sum = 0;
    for (int i = 1; i < int(sqrt(j)) + 1; ++i) {
      if (j % i == 0) {
        divisors_sum++;
        if (i != int(j / i)) {
          divisors_sum++;
        }
      }
    }
    sumdiv += divisors_sum;
  }
  cout << sumdiv << "\\n";
  return 0;
}

Error: TLE

Fixed submission:

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

int make_divisors_sum(int n) {
  ll divisors_sum = 0;
  for (int i = 1; i < int(sqrt(n)) + 1; ++i) {
    if (n % i == 0) {
      divisors_sum++;
      if (i != int(n / i)) {
        divisors_sum++;
      }
    }
  }
  return divisors_sum;
}

int main() {
  int N;
  int sumdiv = 0;
  cin >> N;
  for (int i = 1; i < N; ++i) {
    sumdiv += make_divisors_sum(i);
  }
  cout << sumdiv << "\\n";
  return 0;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define ull unsigned long long
#define pb push_back
#define pf push_front
#define endl "\\n"
#define fast_in_out                                                            \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);

const int mod = 1e7 + 9;

int gcd(int a, int b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

int lcm(int a, int b) { return (a * b) / gcd(a, b); }

int power(int a, int b, int c) {
  if (a == 0)
    return 0;
  if (b == 0)
    return 1;

  int res = 1;
  a = a % c;
  while (b > 0) {
    if (b & 1) {
      res = (res * a) % c;
    }
    a = (a * a) % c;
    b >>= 1;
  }
  return res;
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, ans = 0, ans1 = 0;
  cin >> n;
  vector<int> a(n + 1, 1);
  for (int i = 2; i <= n; i++) {
    for (int j = i; j <= n; j += i)
      a[j]++;
  }
  for (int i = 1; i < n; i++) {
    ans1 += a[i];
  }

  cout << ans1 << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define ull unsigned long long
#define pb push_back
#define pf push_front
#define endl "\\n"
#define fast_in_out                                                            \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);

const int mod = 1e7 + 9;

int gcd(int a, int b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

int lcm(int a, int b) { return (a * b) / gcd(a, b); }

int power(int a, int b, int c) {
  if (a == 0)
    return 0;
  if (b == 0)
    return 1;

  int res = 1;
  a = a % c;
  while (b > 0) {
    if (b & 1) {
      res = (res * a) % c;
    }
    a = (a * a) % c;
    b >>= 1;
  }
  return res;
}
int countDivisors(int n) {
  int cnt = 0;
  for (int i = 1; i <= sqrt(n); i++) {
    if (n % i == 0) {

      if (n / i == i)
        cnt++;

      else // Otherwise count both
        cnt = cnt + 2;
    }
  }
  return cnt;
}
int32_t main() {
  int n, ans = 0;
  cin >> n;

  for (int c = 1; c < n; c++) {
    int k = countDivisors(n - c);
    ans += k;
  }
  cout << ans;
  return 0;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define ull unsigned long long
#define pb push_back
#define pf push_front
#define endl "\\n"
#define fast_in_out                                                            \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);

const int mod = 1e7 + 9;

int gcd(int a, int b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

int lcm(int a, int b) { return (a * b) / gcd(a, b); }

int power(int a, int b, int c) {
  if (a == 0)
    return 0;
  if (b == 0)
    return 1;

  int res = 1;
  a = a % c;
  while (b > 0) {
    if (b & 1) {
      res = (res * a) % c;
    }
    a = (a * a) % c;
    b >>= 1;
  }
  return res;
}

vector<int> arr;

int32_t main() {

  fast_in_out;

  int t = 1;
  // cin>>t;
  while (t--) {
    int n;
    cin >> n;
    int ans = 0;
    arr.resize(n + 1, 0);
    for (int i = 1; i <= n; i++) {
      for (int j = i; j <= n; j += i) {
        arr[j]++;
      }
    }
    for (int i = 1; i < n; i++) {
      int x = n - i;
      ans += arr[x];
    }
    cout << ans << endl;
  }

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define ull unsigned long long
#define pb push_back
#define pf push_front
#define endl "\\n"
#define fast_in_out                                                            \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);

const int mod = 1e7 + 9;

int gcd(int a, int b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

int lcm(int a, int b) { return (a * b) / gcd(a, b); }

int power(int a, int b, int c) {
  if (a == 0)
    return 0;
  if (b == 0)
    return 1;

  int res = 1;
  a = a % c;
  while (b > 0) {
    if (b & 1) {
      res = (res * a) % c;
    }
    a = (a * a) % c;
    b >>= 1;
  }
  return res;
}

int divisors(int n) {
  int ans = 0;
  for (int i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      if (n / i == i) {
        ans += 1;
      } else {
        ans += 2;
      }
    }
  }
  return ans;
}

int32_t main() {

  fast_in_out;

  int t = 1;
  // cin>>t;
  while (t--) {
    int n;
    cin >> n;
    int ans = 0;
    for (int i = 1; i < n; i++) {
      int x = n - i;
      ans += divisors(x);
    }
    cout << ans << endl;
  }

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

#include <bits/stdc++.h>
#define int long long int
#define endl "\\n"
#define mod 1000000007
#define ps(x, noOfDecimal) fixed << setprecision(noOfDecimal) << x
#define IO                                                                     \\
  if (fopen("input.txt", "r")) {                                               \\
    freopen("input.txt", "r", stdin);                                          \\
    freopen("output.txt", "w", stdout);                                        \\
  }                                                                            \\
  std::ios::sync_with_stdio(false);
using namespace std;

signed main() {

  IO const int N = 1000000;
  vector<vector<int>> divisors(N + 1);
  for (int i = 1; i <= N; i++) {
    for (int j = i; j <= N; j += i) {
      divisors[j].push_back(i);
    }
  }

  int n;
  cin >> n;
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    cnt += divisors[n - i].size();
  }
  cout << cnt;

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define int long long int
#define endl "\\n"
#define mod 1000000007
#define ps(x, noOfDecimal) fixed << setprecision(noOfDecimal) << x
#define IO                                                                     \\
  if (fopen("input.txt", "r")) {                                               \\
    freopen("input.txt", "r", stdin);                                          \\
    freopen("output.txt", "w", stdout);                                        \\
  }                                                                            \\
  std::ios::sync_with_stdio(false);
using namespace std;

int cntd(int n) {
  int cnt = 0;
  for (int i = 1; i <= sqrt(n); i++) {
    if (n % i == 0) {
      if (n / i == i)
        cnt++;
      else
        cnt = cnt + 2;
    }
  }
  return cnt;
}

signed main() {

  IO int t = 1;
  // cin >> t;
  while (t--) {

    int n;
    cin >> n;
    int cnt = 0;
    for (int i = 1; i <= n; i++) {
      cnt += cntd(n - i);
    }

    cout << cnt;
  }

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

#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
typedef pair<int, int> pii;
typedef long long ll;

int n;
ll sum;

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

  cin >> n;
  for (int i = 1; i * i <= n; i++) {
    for (int j = i; j * i < n; j++) {
      if (i == j) {
        sum++;
      } else {
        sum += 2;
      }
    }
  }
  cout << sum << "\\n";
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
typedef pair<int, int> pii;
typedef long long ll;

int n;
ll sum;

ll solve(int x) {
  ll ans = 0;
  for (int i = 1; i * i <= x; i++) {
    if (x % i == 0) {
      if (i * i == x) {
        ans++;
      } else {
        ans += 2;
      }
    }
  }
  return ans;
}

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

  cin >> n;
  for (int i = 1; i < n; i++) {
    sum += solve(n - i);
  }
  cout << sum << "\\n";
  return 0;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  ll n;
  cin >> n;
  ll ans = 0;
  rep(i, n - 1) { ans += (n - 1) / (i + 1); }
  cout << ans;

  return 0;
}


Error: TLE

Fixed submission:

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

template <typename T> map<T, T> prime_factor(T n) {
  map<T, T> ret;
  for (T i = 2; i * i <= n; i++) {
    T tmp = 0;
    while (n % i == 0) {
      tmp++;
      n /= i;
    }
    ret[i] = tmp;
  }
  if (n != 1)
    ret[n] = 1;
  return ret;
}

template <typename T> T divisor_num(T N) {
  map<T, T> pf = prime_factor(N);
  T ret = 1;
  for (auto p : pf) {
    ret *= (p.second + 1);
  }
  return ret;
}

int main() {
  ll n;
  cin >> n;
  vector<ll> p(1000000);
  rep(i, 1000000) { p[i] = divisor_num(i + 1); }
  ll ans = 0;
  rep(i, n - 1) { ans = ans + p[i]; }
  cout << ans;
  return 0;
}