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

/////////////////////////////////TEST CASES////////////////////////////////////
/*
 */
/////////////////////////////////////CODE//////////////////////////////////////
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORD(i, a, b) for (ll i = a; i > b; i--)
#define fastio ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define PI 3.14159265
typedef long long ll;
#define vl vector<ll>
#define IN(inp)                                                                \\
  ll inp;                                                                      \\
  cin >> inp;
#define pb push_back
#define all(a) a.begin(), a.end()
#define FR(i, a) for (auto &i : a)
#define rvl(a, n)                                                              \\
  vl a;                                                                        \\
  FOR(i, 0, n) {                                                               \\
    IN(in);                                                                    \\
    a.pb(in);                                                                  \\
  }
#define what(A) cout << #A << " is " << A << endl;
ll MAX = 100000000000;
ll MOD = 1000000007;
void solve() {
  IN(n);
  ll cnt = 0;
  FOR(i, 1, n) {
    if (n % i != 0)
      cnt += n / i;
    else
      cnt += n / i - 1;
  }
  cout << cnt << endl;
}
int main() {
  fastio
      // freopen("input.txt", "rt", stdin);
      // freopen("output.txt", "wt", stdout);
      ll test = 1;
  // cin >> test;
  while (test--) {
    solve();
  }
}

Error: TLE

Fixed submission:

/////////////////////////////////TEST CASES////////////////////////////////////
/*
 */
/////////////////////////////////////CODE//////////////////////////////////////
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORD(i, a, b) for (ll i = a; i > b; i--)
#define fastio ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define PI 3.14159265
typedef long long ll;
#define vl vector<ll>
#define IN(inp)                                                                \\
  ll inp;                                                                      \\
  cin >> inp;
#define pb push_back
#define all(a) a.begin(), a.end()
#define FR(i, a) for (auto &i : a)
#define rvl(a, n)                                                              \\
  vl a;                                                                        \\
  FOR(i, 0, n) {                                                               \\
    IN(in);                                                                    \\
    a.pb(in);                                                                  \\
  }
#define what(A) cout << #A << " is " << A << endl;
ll MAX = 100000000000;
ll MOD = 1000000007;
void solve() {
  IN(n);
  ll cnt = 0;
  FOR(i, 1, n) {
    ll k = n - i;
    for (int j = 1; j * j <= k; j++) {
      if (k % j == 0) {
        cnt++;
        if (k / j != j) {
          cnt++;
        }
      }
    }
  }
  cout << cnt;
}
int main() {
  fastio
      // freopen("input.txt", "rt", stdin);
      // freopen("output.txt", "wt", stdout);
      ll test = 1;
  // cin >> test;
  while (test--) {
    solve();
  }
}