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

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using pl = pair<ll, ll>;
const ll INF = ll(1e18);
const ll mod = ll(1e9 + 7);
const double pi = acos(-1);
#define rep0(i, n) for (ll(i) = 0; (i) < (n); ++(i))
#define rrep0(i, n) for (ll(i) = (n)-1; (i) >= 0; --(i))
#define rep1(i, n) for (ll(i) = 1; (i) <= (n); ++(i))
#define rrep1(i, n) for (ll(i) = (n); (i) >= 1; --(i))
#define nfor(i, a, b) for (ll(i) = (a); (i) < (b); ++(i))
#define rnfor(i, a, b) for (ll(i) = (b)-1; (i) >= (a); --(i))
#define pf(x) cout << (x) << endl
#define all(x) (x).begin(), (x).end()
#define yes pf("Yes")
#define no pf("No")
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
const int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};

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

ll lcm(ll a, ll b) {
  ll g = gcd(a, b);
  return a / g * b;
}

ll factorial(ll n) {
  ll ans = 1;
  rep1(i, n) {
    ans *= i;
    ans %= mod;
  }
  return ans;
}

ll power(ll a, ll b) {
  ll ans = 1;
  a %= mod;
  while (b) {
    if (b & 1LL)
      ans = ans * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return ans % mod;
}

// modの値の確認をすること
int main() {
  ll n;
  cin >> n;
  rep1(i, n) {
    ll c = 0;
    for (ll x = 1; x * x <= i; ++x) {
      ll k = i - x * x;
      for (ll y = 1; y * y <= k; ++y) {
        ll f = k - y * y;
        ll l = 1, r = 100;
        while (l <= r) {
          ll z = (l + r) / 2;
          ll t = z * z + x * z + z * y + y * x;
          if (f - t > 0)
            l = z + 1;
          else if (f - t < 0)
            r = z - 1;
          else {
            ++c;
            break;
          }
        }
      }
    }
    pf(c);
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using pl = pair<ll, ll>;
const ll INF = ll(1e18);
const ll mod = ll(1e9 + 7);
const double pi = acos(-1);
#define rep0(i, n) for (ll(i) = 0; (i) < (n); ++(i))
#define rrep0(i, n) for (ll(i) = (n)-1; (i) >= 0; --(i))
#define rep1(i, n) for (ll(i) = 1; (i) <= (n); ++(i))
#define rrep1(i, n) for (ll(i) = (n); (i) >= 1; --(i))
#define nfor(i, a, b) for (ll(i) = (a); (i) < (b); ++(i))
#define rnfor(i, a, b) for (ll(i) = (b)-1; (i) >= (a); --(i))
#define pf(x) cout << (x) << endl
#define all(x) (x).begin(), (x).end()
#define yes pf("Yes")
#define no pf("No")
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
const int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};

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

ll lcm(ll a, ll b) {
  ll g = gcd(a, b);
  return a / g * b;
}

ll factorial(ll n) {
  ll ans = 1;
  rep1(i, n) {
    ans *= i;
    ans %= mod;
  }
  return ans;
}

ll power(ll a, ll b) {
  ll ans = 1;
  a %= mod;
  while (b) {
    if (b & 1LL)
      ans = ans * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return ans % mod;
}

// modの値の確認をすること
int main() {
  ll n;
  cin >> n;
  rep1(i, n) {
    ll c = 0;
    for (ll x = 1; x * x <= i; ++x)
      for (ll y = 1; y * y <= i - x * x; ++y)
        for (ll z = 1; z * z <= i - x * x - y * y; ++z)
          if (x * x + y * y + z * z + x * z + z * y + y * x == i)
            ++c;
    pf(c);
  }
  return 0;
}