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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define pb push_back
#define eb emplace_back
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define cinarr(A, len)                                                         \\
  for (int i = 0; i < len; i++) {                                              \\
    cin >> A[i];                                                               \\
  }
#define coutarr(A, len)                                                        \\
  for (int i = 0; i < len; i++) {                                              \\
    cout << A[i] << ' ';                                                       \\
  }                                                                            \\
  cout << endl
#define coutin(V)                                                              \\
  for (auto &i : V) {                                                          \\
    cout << i << ' ';                                                          \\
  }                                                                            \\
  cout << endl // for vect and set
#define coutmap(U)                                                             \\
  for (auto &i : U) {                                                          \\
    cout << i.first << "->" << i.second << ", ";                               \\
  }                                                                            \\
  cout << endl // for map
#define deb(x) cerr << #x << '\\t' << x << endl
const int imax = numeric_limits<int>::max(), imin = numeric_limits<int>::min();
const long long lmax = numeric_limits<long long>::max(),
                lmin = numeric_limits<long long>::min();
/*========================================================================*/
/* strategi/note:



/================================*/

bool Svd = 0;
void solve() {
  Svd = 1;
  ll n;
  cin >> n;
  ll ans = 0;
  for (ll a = 1; a <= n; a++) {
    // cout << a << ' ' << b << ' ' << n-a*b << endl;
    ans += (n / a) - (n % a == 0 ? 1 : 0);
  }
  cout << ans << endl;
}

/*========================================================================*/

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  // cout<<fixed<<setprecision( ); // iomanip **

  solve();
  // int t;cin>>t;while(t--){solve();}

  if (!Svd)
    cout << "solve() function blm dipanggil!" << endl;
  // cout.flush(); cin.get();
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define pb push_back
#define eb emplace_back
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define cinarr(A, len)                                                         \\
  for (int i = 0; i < len; i++) {                                              \\
    cin >> A[i];                                                               \\
  }
#define coutarr(A, len)                                                        \\
  for (int i = 0; i < len; i++) {                                              \\
    cout << A[i] << ' ';                                                       \\
  }                                                                            \\
  cout << endl
#define coutin(V)                                                              \\
  for (auto &i : V) {                                                          \\
    cout << i << ' ';                                                          \\
  }                                                                            \\
  cout << endl // for vect and set
#define coutmap(U)                                                             \\
  for (auto &i : U) {                                                          \\
    cout << i.first << "->" << i.second << ", ";                               \\
  }                                                                            \\
  cout << endl // for map
#define deb(x) cerr << #x << '\\t' << x << endl
const int imax = numeric_limits<int>::max(), imin = numeric_limits<int>::min();
const long long lmax = numeric_limits<long long>::max(),
                lmin = numeric_limits<long long>::min();
/*========================================================================*/
/* strategi/note:



/================================*/

bool Svd = 0;
void solve() {
  Svd = 1;
  ll n;
  cin >> n;
  ll ans = 0;
  ll to = ceil(sqrt(n));
  for (ll a = 1; a <= n; a++) {
    for (ll b = 1; b <= n; b++) {
      if (a * b < n) {
        // cout << a << ' ' << b << ' ' << n-a*b << endl;
        ans++;
      }
    }
  }
  cout << ans << endl;
}

/*========================================================================*/

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  // cout<<fixed<<setprecision( ); // iomanip **

  solve();
  // int t;cin>>t;while(t--){solve();}

  if (!Svd)
    cout << "solve() function blm dipanggil!" << endl;
  // cout.flush(); cin.get();
  return 0;
}