Problem p02548 (C++) — buggy submission, verdict: Runtime Error

// THIS IS THE AATMANIRBHAR SOLUTION I FOUND..!!!!!
#include <bits/stdc++.h>
using namespace std;
#define int long long
// #define int double
// #define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define P push
#define vvi vector<vector<int>>
#define vi vector<int>
#define vf vector<float>
#define vc vector<char>
#define vs vector<string>
#define pii vector<pair<int, int>>
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define sort(v) sort(all(v))
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(j, a, b) for (int j = a - 1; j >= b; j--)
#define binod                                                                  \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
const int N = 1e9 + 7, N1 = 1e7 + 5, N2 = 1e6 + 3, N3 = 1e5 + 3;
#define IX INT_MAX
#define IM INT_MIN

void solve() {
  int n;
  cin >> n;
  int cnt = 0;
  vi ans(n + 5, 0);
  for (int i = 1; i < sqrt(n); i++) {
    for (int j = i; j < n; j++) {
      if (i == j and i * i < n)
        cnt++;
      else if (i * j < n)
        cnt += 2;
      else
        break;
    }
  }
  cout << cnt;
}

signed main() {
  binod;
  int t1 = 1;
  // cin>>t1;
  //  cout<<fixed<<setprecision(9);
  while (t1--) {
    solve();
    cout << endl;
  }
}

// Don't judge me or anyone
// this is life,
// not a reality show


Error: -6
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc


Fixed submission:

// THIS IS THE AATMANIRBHAR SOLUTION I FOUND..!!!!!
#include <bits/stdc++.h>
using namespace std;
#define int long long
// #define int double
// #define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define P push
#define vvi vector<vector<int>>
#define vi vector<int>
#define vf vector<float>
#define vc vector<char>
#define vs vector<string>
#define pii vector<pair<int, int>>
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define sort(v) sort(all(v))
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(j, a, b) for (int j = a - 1; j >= b; j--)
#define binod                                                                  \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
const int N = 1e9 + 7, N1 = 1e7 + 5, N2 = 1e6 + 3, N3 = 1e5 + 3;
#define IX INT_MAX
#define IM INT_MIN

// vi v(N2,0);
// void SieveOfEratosthenes(int n)
// {
//     bool prime[n+1];
//     memset(prime, true, sizeof(prime));
//     for (int p=2; p*p<=n; p++)
//     {
//         if (prime[p] == true)
//         {
//             for (int i=p*p; i<=n; i += p)
//                 prime[i] = false;
//         }
//     }
//     for (int p=2; p<=n; p++)
//       if (prime[p])
//           v[p]=1;
// }

void solve() {
  int n;
  cin >> n;
  int cnt = 0;
  vi ans(n + 5, 0);
  for (int i = 1; i < sqrt(n); i++) {
    for (int j = i; j < n; j++) {
      if (i == j and i * i < n)
        cnt--;
      if (i * j < n)
        cnt += 2;
      else
        break;
    }
    // cout<<cnt<<" ";
  }
  cout << cnt;
}

signed main() {
  binod;
  int t1 = 1;
  cin >> t1;
  // cout<<fixed<<setprecision(9);
  // SieveOfEratosthenes(N2);
  while (t1--) {
    solve();
    cout << endl;
  }
}

// Don't judge me or anyone
// this is life,
// not a reality show