Problem p02548 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>

//{ START
using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (n - 1); i > (a - 1); --i)
#define arep(i, x) for (auto &&i : (x))
#define irep(i, x) for (auto i = (x).begin(); i != (x).end(); ++i)
#define rirep(i, x) for (auto i = (x).rbegin(); i != (x).rend(); ++i)
// 降順はgreater<T>()
#define all(x) (x).begin(), (x).end()
#define rv(s) reverse((s).begin(), (s).end())
// gcd lcmはそのままok
#define gcd(a, b) __gcd(a, b)
#define bits(n) (1LL << (n))
#define pcnt(x) __builtin_popcountll(x)
// 配列内等要素削除
#define Unique(x) (x).erase(unique((x).begin(), (x).end()), (x).end())
#define Fixed(n) fixed << setprecision(n)
// 総和
#define sowa(n) (((n) * ((n) + 1)) / 2)
#define updiv(a, b) ((a + b - 1) / b)
#define cauto const auto &
using P = pair<int, int>;
using Graph = vector<vector<P>>;
template <class T> // 昇順
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <class T> // 降順
using max_heap = priority_queue<T>;
template <class A, class B> using umap = unordered_map<A, B>;
template <class A> using uset = unordered_set<A>;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) { // 多次元初期化
  std::fill((T *)array, (T *)(array + N), val);
}
template <class A, class B>
bool chmax(A &a, const B &b) { // 最大値更新 返り値はbool
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class A, class B>
bool chmin(A &a, const B &b) { // 最小値更新 返り値はbool
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, 1, 1, -1, -1};
constexpr int INF = 0x3f3f3f3f;
constexpr int LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9 + 7;
constexpr int mod2 = 998244353;
//} END

// 約数列挙 o(√n)
vector<int> divisor(int n) {
  vector<int> res;
  for (int i = 1; i * i <= n; ++i) {
    if (n % i == 0) {
      res.push_back(i);
      if (i != n / i)
        res.push_back(n / i);
    }
  }
  return res;
}

// エラトトステネスの篩を用いた高速な素因数分解
vector<int> sieve_prime_factor(size_t max) {
  vector<bool> IsPrime(max + 1, true);
  vector<int> prime(max + 1), spf(max + 1);
  IsPrime[0] = IsPrime[1] = false; // 0,1の初期化
  for (size_t i = 2; i <= max; ++i) {
    if (IsPrime[i] == true)
      for (size_t j = i; j <= max; j += i) {
        IsPrime[j] = false; // 非素数を記録
        prime[j] = i;       // 非素数を保存
      }
  }
  // prime[i]を用いて各iの素因数を列挙可能
  for (size_t i = 1; i <= max; ++i) {
    int now = i;
    while (now != 1) {
      spf[prime[now]]++;
      now /= prime[now];
    }
  }
  return spf;
}

signed main(void) {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  int n;
  cin >> n;
  // int spf = sieve_prime_factor(n+1);
  int cnt = 0;
  if (n == 2) {
    cout << 1 << '\n';
    return 0;
  }
  rep(i, 1, n) {
    auto now = divisor(n - i);
    cnt += now.size();
    // cout << now.size() << ' ';
    // cout << cnt << '\n';
  }
  cout << cnt << '\n';
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>

//{ START
using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (n - 1); i > (a - 1); --i)
#define arep(i, x) for (auto &&i : (x))
#define irep(i, x) for (auto i = (x).begin(); i != (x).end(); ++i)
#define rirep(i, x) for (auto i = (x).rbegin(); i != (x).rend(); ++i)
// 降順はgreater<T>()
#define all(x) (x).begin(), (x).end()
#define rv(s) reverse((s).begin(), (s).end())
// gcd lcmはそのままok
#define gcd(a, b) __gcd(a, b)
#define bits(n) (1LL << (n))
#define pcnt(x) __builtin_popcountll(x)
// 配列内等要素削除
#define Unique(x) (x).erase(unique((x).begin(), (x).end()), (x).end())
#define Fixed(n) fixed << setprecision(n)
// 総和
#define sowa(n) (((n) * ((n) + 1)) / 2)
#define updiv(a, b) ((a + b - 1) / b)
#define cauto const auto &
using P = pair<int, int>;
using Graph = vector<vector<P>>;
template <class T> // 昇順
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <class T> // 降順
using max_heap = priority_queue<T>;
template <class A, class B> using umap = unordered_map<A, B>;
template <class A> using uset = unordered_set<A>;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) { // 多次元初期化
  std::fill((T *)array, (T *)(array + N), val);
}
template <class A, class B>
bool chmax(A &a, const B &b) { // 最大値更新 返り値はbool
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class A, class B>
bool chmin(A &a, const B &b) { // 最小値更新 返り値はbool
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, 1, 1, -1, -1};
constexpr int INF = 0x3f3f3f3f;
constexpr int LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9 + 7;
constexpr int mod2 = 998244353;
//} END

// 約数列挙 o(√n)
vector<int> divisor(int n) {
  vector<int> res;
  for (int i = 1; i * i <= n; ++i) {
    if (n % i == 0) {
      res.push_back(i);
      if (i != n / i)
        res.push_back(n / i);
    }
  }
  return res;
}

// エラトトステネスの篩を用いた高速な素因数分解
vector<int> sieve_prime_factor(size_t max) {
  vector<bool> IsPrime(max + 1, true);
  vector<int> prime(max + 1), spf(max + 1);
  IsPrime[0] = IsPrime[1] = false; // 0,1の初期化
  for (size_t i = 2; i <= max; ++i) {
    if (IsPrime[i] == true)
      for (size_t j = i; j <= max; j += i) {
        IsPrime[j] = false; // 非素数を記録
        prime[j] = i;       // 非素数を保存
      }
  }
  // prime[i]を用いて各iの素因数を列挙可能
  for (size_t i = 1; i <= max; ++i) {
    int now = i;
    while (now != 1) {
      spf[prime[now]]++;
      now /= prime[now];
    }
  }
  return spf;
}

signed main(void) {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  int n;
  cin >> n;
  // int spf = sieve_prime_factor(n+1);
  int cnt = 0;
  rep(i, 1, n + 1) {
    rep(j, 1, n + 1) {
      if (i * j >= n)
        break;
      else
        ++cnt;
    }
  }
  cout << cnt << '\n';
  return 0;
}