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

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\\n"
#define pb push_back
#define f(i, n) for (i = 0; i < n; i++)
#define F(i, a, b) for (i = a; a <= b; i++)
#define arr(a, n)                                                              \\
  for (i = 0; i < n; i++)                                                      \\
    cin >> a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a, a + n);
#define sr() sort(a, a + n, greater<ll>());
#define v() sort(v.begin(), v.end());
#define vr() sort(v.begin(), v.end(), greater<ll>());
#define mod 1000000007
#define fast()                                                                 \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
ll gcd(ll a, ll b) {
  if (!b)
    return a;
  return gcd(b, a % b);
}
ll power(ll x, ll y, ll p) {
  ll res = 1;
  x %= p;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
int main() {
#ifndef ONLINE_JUDGE
  // for getting input from input.txt
  freopen("input.txt", "r", stdin);
  // for writing output to output.txt
  freopen("output.txt", "w", stdout);
#endif

  fast();
  // ll t;cin>>t;while(t--)
  {
    ll n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
      ll counter = 0;
      for (int a = 1; a <= sqrt(n); a++) {
        for (int b = 1; b <= sqrt(n); b++) {
          ll c = 0;
          ll x = i - (a * a) - (b * b) - (a * b);
          ll A = 1, B = (a + b), C = -1ll * x;
          ll f = B * B - (4 * A * C);

          if (f >= 0) {
            float d = float(sqrt(float(f)));
            d = d - B;
            /*if(i==6&&a==1&&b==1)
            {
              cerr<<"f = "<<f<<" B = "<<B<<" C = "<<C<<" float d = "<<d<<endl;
            }*/
            ll YY = d;
            if ((YY % 2) == 0) {
              c = YY;
              c /= 2;
              if (c > 0) {
                ll temp =
                    (a * a) + (b * b) + (c * c) + (a * b) + (b * c) + (a * c);
                if (temp == i) {
                  counter++;
                }
              }
            }
          }
          /*if(i==6&&a==1&&b==1)
            {
              cerr<<a<<" "<<b<<" "<<c<<endl;
            }*/
        }
      }
      cout << counter << endl;
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\\n"
#define pb push_back
#define f(i, n) for (i = 0; i < n; i++)
#define F(i, a, b) for (i = a; a <= b; i++)
#define arr(a, n)                                                              \\
  for (i = 0; i < n; i++)                                                      \\
    cin >> a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a, a + n);
#define sr() sort(a, a + n, greater<ll>());
#define v() sort(v.begin(), v.end());
#define vr() sort(v.begin(), v.end(), greater<ll>());
#define mod 1000000007
#define fast()                                                                 \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
ll gcd(ll a, ll b) {
  if (!b)
    return a;
  return gcd(b, a % b);
}
ll power(ll x, ll y, ll p) {
  ll res = 1;
  x %= p;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
int main() {
#ifndef ONLINE_JUDGE
  // for getting input from input.txt
  freopen("input.txt", "r", stdin);
  // for writing output to output.txt
  freopen("output.txt", "w", stdout);
#endif

  fast();
  // ll t;cin>>t;while(t--)
  {
    ll n, c = 0;
    cin >> n;
    for (int i = 1; i <= n; i++) {
      ll c = 0;
      for (int j = 1; j <= sqrt(n); j++) {
        for (int k = 1; k <= sqrt(n); k++) {
          for (int l = 1; l <= sqrt(n); l++) {
            ll temp = j * j + k * k + l * l + j * k + k * l + l * j;
            if (temp == i) {
              c++;
            } else if (temp > i) {
              break;
            }
          }
        }
      }
      cout << c << endl;
    }
  }
  return 0;
}