Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

// #include <bits/stdc++.h>
#include <algorithm>
#include <climits>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stack>
#include <string.h>
#include <unordered_map>
#include <vector>
using namespace std;
const int INF = 1e9;
#define ll long long
#define int ll
#define fast                                                                   \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define testcase while (tt--)
#define pb push_back
#define endl "\\n"
#define deb1(x) cout << #x << ": " << x << endl
#define deb2(x, y) cout << #x << ": " << x << " | " << #y << ": " << y << endl
#define deb3(x, y, z)                                                          \\
  cout << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": "   \\
       << z << endl
#define deb4(x, y, z, w)                                                       \\
  cout << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": "   \\
       << z << " | " << #w << ": " << w << endl
#define deb5(a, b, c, d, e)                                                    \\
  cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": "   \\
       << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(a) int((a).size())
#define pii pair<int, int>
#define fi first
#define se second
#define ld long double
#define vii vector<int>
#define all(v) v.begin(), v.end()
#define prec(n) fixed << setprecision(n)
#define printclock                                                             \\
  cerr << "Time : " << 1000 * (ld)clock() / (ld)CLOCKS_PER_SEC << "ms\\n";
const int MOD = 998244353;
const int MOD2 = 429496729;
const ll LINF = (ll)1e18;
const ld PI = acos((ld)-1);
const ld EPS = 1e-12;
inline ll gcd(ll a, ll b) {
  ll r;
  while (b) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}
inline ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
inline ll fpow(ll n, ll k, int p = MOD) {
  ll r = 1;
  for (; k; k >>= 1) {
    if (k & 1)
      r = r * n % p;
    n = n * n % p;
  }
  return r;
}
template <class T> inline int chkmin(T &a, const T &val) {
  return val < a ? a = val, 1 : 0;
}
template <class T> inline int chkmax(T &a, const T &val) {
  return a < val ? a = val, 1 : 0;
}
inline void addmod(int &a, int val, int p = MOD) {
  if ((a = (a + val)) >= p)
    a -= p;
}
inline void submod(int &a, int val, int p = MOD) {
  if ((a = (a - val)) < 0)
    a += p;
}
inline int mult(int a, int b, int p = MOD) { return (ll)a * b % p; }
inline int inv(int a, int p = MOD) { return fpow(a, p - 2, p); }
template <class T> inline void get_arr(T arr[], int n) {
  for (int i = 0; i < n; i++)
    cin >> arr[i];
}
template <class T> inline void print_arr(T arr[], int n) {
  for (int i = 0; i < n; i++)
    cout << arr[i] << " ";
  cout << endl;
}
template <class T> inline void print_vec(vector<T> arr) {
  for (int i = 0; i < arr.size(); i++)
    cout << arr[i] << " ";
  cout << endl;
}

// const int N=1e7+5;
// int prime[N]={0};

int32_t main() {
  fast;
#ifndef ONLINE_JUDGE
  freopen("./input.txt", "r", stdin);
  // freopen("./output.txt","w",stdout);
#endif
  int tt = 1;
  // cin >> tt;
  // int ttt=tt;
  testcase {
    int n;
    cin >> n;
    int ans = 0;
    for (int i = 1; i < n; i++) {
      ans += n / i;
      if (n % i == 0)
        ans--;
    }
    cout << ans << endl;
  }
  // printclock;
  return 0;
}

Error: TLE

Fixed submission:

// #include <bits/stdc++.h>
#include <algorithm>
#include <climits>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stack>
#include <string.h>
#include <unordered_map>
#include <vector>
using namespace std;
const int INF = 1e9;
#define ll long long
#define int ll
#define fast                                                                   \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define testcase while (tt--)
#define pb push_back
#define endl "\\n"
#define deb1(x) cout << #x << ": " << x << endl
#define deb2(x, y) cout << #x << ": " << x << " | " << #y << ": " << y << endl
#define deb3(x, y, z)                                                          \\
  cout << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": "   \\
       << z << endl
#define deb4(x, y, z, w)                                                       \\
  cout << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": "   \\
       << z << " | " << #w << ": " << w << endl
#define deb5(a, b, c, d, e)                                                    \\
  cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": "   \\
       << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(a) int((a).size())
#define pii pair<int, int>
#define fi first
#define se second
#define ld long double
#define vii vector<int>
#define all(v) v.begin(), v.end()
#define prec(n) fixed << setprecision(n)
#define printclock                                                             \\
  cerr << "Time : " << 1000 * (ld)clock() / (ld)CLOCKS_PER_SEC << "ms\\n";
const int MOD = 998244353;
const int MOD2 = 429496729;
const ll LINF = (ll)1e18;
const ld PI = acos((ld)-1);
const ld EPS = 1e-12;
inline ll gcd(ll a, ll b) {
  ll r;
  while (b) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}
inline ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
inline ll fpow(ll n, ll k, int p = MOD) {
  ll r = 1;
  for (; k; k >>= 1) {
    if (k & 1)
      r = r * n % p;
    n = n * n % p;
  }
  return r;
}
template <class T> inline int chkmin(T &a, const T &val) {
  return val < a ? a = val, 1 : 0;
}
template <class T> inline int chkmax(T &a, const T &val) {
  return a < val ? a = val, 1 : 0;
}
inline void addmod(int &a, int val, int p = MOD) {
  if ((a = (a + val)) >= p)
    a -= p;
}
inline void submod(int &a, int val, int p = MOD) {
  if ((a = (a - val)) < 0)
    a += p;
}
inline int mult(int a, int b, int p = MOD) { return (ll)a * b % p; }
inline int inv(int a, int p = MOD) { return fpow(a, p - 2, p); }
template <class T> inline void get_arr(T arr[], int n) {
  for (int i = 0; i < n; i++)
    cin >> arr[i];
}
template <class T> inline void print_arr(T arr[], int n) {
  for (int i = 0; i < n; i++)
    cout << arr[i] << " ";
  cout << endl;
}
template <class T> inline void print_vec(vector<T> arr) {
  for (int i = 0; i < arr.size(); i++)
    cout << arr[i] << " ";
  cout << endl;
}

// const int N=1e7+5;
// int prime[N]={0};

int32_t main() {
  fast;
#ifndef ONLINE_JUDGE
  freopen("./input.txt", "r", stdin);
  // freopen("./output.txt","w",stdout);
#endif
  int tt = 1;
  // cin >> tt;
  // int ttt=tt;
  testcase {

    const int N = 1e6 + 8;
    int arr[N] = {0};
    for (int i = 1; i < N; i++) {
      for (int j = 1; j * j <= i; j++) {
        if (i % j == 0) {
          arr[i]++;
          if (i / j != j)
            arr[i]++;
        }
      }
    }
    int n;
    cin >> n;
    int ans = 0;
    for (int i = 1; i < n; i++) {
      ans += arr[n - i];
    }
    cout << ans << endl;
  }
  // printclock;
  return 0;
}