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

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

#define fast()                                                                 \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define ll long long int
#define test()                                                                 \\
  ll t;                                                                        \\
  cin >> t;                                                                    \\
  while (t--)
#define lp0(i, begin, end) for (ll i = begin; i < end; i++)
#define lp1(i, begin, end) for (ll i = begin; i <= end; i++)
#define rlp(i, begin, end) for (ll i = end; i >= begin; i--)
#define prec(n) fixed << setprecision(n)
#define initial(a, i) memset(a, i, sizeof(a))
#define pb push_back
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define F first
#define S second
#define all(a) (a).begin(), (a).end()
#define BPC(x) __builtin_popcountll(x)
#define gcd(a, b) __gcd(a, b)

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

ll power(ll x, ll n) {
  ll result = 1;
  while (n) {
    if (n & 1)
      result = result * x;
    n = n / 2;
    x = x * x;
  }
  return result;
}

// Solution Function
void solution() {
  // cout<<compte<<"\\n";
  ll n;
  cin >> n;

  ll cnt = 1;

  ll ans = 0;
  for (ll i = 1; i <= n; i++) {
    bool c = false;
    for (ll j = 1; j <= n; j++) {
      if (i * j < n) {
        c = true;
        ans++;
      } else
        break;
    }
    if (c == false)
      break;
  }
  cout << ans;
}
// Driver Function
int main() {
  ll compte = 1;
  // test()
  //{
  solution();
  compte++;
  //}
  return 0;
}


Error: TLE

Fixed submission:

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

#define fast()                                                                 \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define ll long long int
#define test()                                                                 \\
  ll t;                                                                        \\
  cin >> t;                                                                    \\
  while (t--)
#define lp0(i, begin, end) for (ll i = begin; i < end; i++)
#define lp1(i, begin, end) for (ll i = begin; i <= end; i++)
#define rlp(i, begin, end) for (ll i = end; i >= begin; i--)
#define prec(n) fixed << setprecision(n)
#define initial(a, i) memset(a, i, sizeof(a))
#define pb push_back
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define F first
#define S second
#define all(a) (a).begin(), (a).end()
#define BPC(x) __builtin_popcountll(x)
#define gcd(a, b) __gcd(a, b)

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

ll power(ll x, ll n) {
  ll result = 1;
  while (n) {
    if (n & 1)
      result = result * x;
    n = n / 2;
    x = x * x;
  }
  return result;
}

ll countWays(ll n) {
  // To store count of such pairs
  ll count = 0;
  ll cnt1 = 0;

  // Counting number of pairs
  // upto sqrt(n) - 1
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0 && ((n / i) == i)) {
      cnt1++;
    } else if (n % i == 0)
      count++;
  }
  // To return count of pairs
  // cout<<n <<" "<<count<<"\\n";
  return (count * 2 + cnt1);
}

// Solution Function
void solution() {
  // cout<<compte<<"\\n";
  ll n;
  cin >> n;

  ll cnt = 1;

  for (ll i = 2; i < n; i++) {
    ll divi = countWays(i);
    cnt += divi;
  }
  cout << cnt << "\\n";
}
// Driver Function
int main() {
  ll compte = 1;
  // test()
  //{
  solution();
  compte++;
  //}
  return 0;
}