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

#include <bits/stdc++.h>
#define ios                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define ll long long
using namespace std;
// bitset<8>set1(p);
// __builtin_popcountll(x);
// bitset<100> b("1010");
long long power(long long a, long long b) {
  // a %= m;
  long long res = 1;
  while (b > 0) {
    if (b & 1)
      res = res * a;
    a = a * a;
    b >>= 1;
  }
  return res;
}
ll int binomial(ll int n, ll int k) {
  ll int C[k + 1];
  memset(C, 0, sizeof(C));

  C[0] = 1; // nC0 is 1

  for (ll int i = 1; i <= n; i++) {
    // Compute next row of pascal triangle using
    // the previous row
    for (int j = min(i, k); j > 0; j--)
      C[j] = C[j] + C[j - 1];
  }
  return C[k];
}
vector<int> pr;
bool prime[10000000];
void Sieve(ll int n) {
  memset(prime, true, sizeof(prime));
  prime[1] = false;

  for (int p = 2; p * p <= n; p++) {
    if (prime[p] == true) {
      pr.push_back(p);
      for (int i = p * p; i <= n; i += p)
        prime[i] = false;
    }
  }
}

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

// Function to find gcd of array of
// numbers
int find(int arr[], int n) {
  int result = arr[0];
  for (int i = 1; i < n; i++) {
    result = gcd(arr[i], result);

    if (result == 1) {
      return 1;
    }
  }
  return result;
}

// It reurns Fn,Fn+1
pair<int, int> fib(int n) {
  if (n == 0)
    return {0, 1};

  auto p = fib(n >> 1);
  int c = p.first * (2 * p.second - p.first);
  int d = p.first * p.first + p.second * p.second;
  if (n & 1)
    return {d, c + d};
  else
    return {c, d};
}
void reverse(string &str) {
  int n = str.length();

  // Swap character starting from two
  // corners
  for (int i = 0; i < n / 2; i++)
    swap(str[i], str[n - i - 1]);
}

string fun(string s) {
  for (int i = 0; i < s.length(); i++) {
    if (s[i] == 'O' || s[i] == 'o') {
      s[i] = '0';
    } else if (s[i] == 'l' || s[i] == 'I' || s[i] == 'L' || s[i] == 'i') {
      s[i] = '1';
    } else if (isupper(s[i])) {
      s[i] = tolower(s[i]);
    }
  }
  return s;
}

int main() {
  ios;
  ll int n;
  cin >> n;
  map<int, int> mp;
  for (int i = 1; i <= 100; i++) {
    for (int j = 1; j <= 100; j++) {
      for (int k = 1; k <= 100; k++) {
        ll int p = (i * i) + (j * j) + (k * k) + (i * j) + (j * k) + (i * k);
        /*if(i==j && j==k)
        {
            mp[p]+=1;
        }
        else if(i==j || j==k || k==i)
        {
            mp[p]+=3;
        }
        else
        {
            mp[p]+=6;
        }*/
        mp[p]++;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    cout << mp[i] << endl;
  }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ios                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define ll long long
using namespace std;
// bitset<8>set1(p);
// __builtin_popcountll(x);
// bitset<100> b("1010");
long long power(long long a, long long b) {
  // a %= m;
  long long res = 1;
  while (b > 0) {
    if (b & 1)
      res = res * a;
    a = a * a;
    b >>= 1;
  }
  return res;
}
ll int binomial(ll int n, ll int k) {
  ll int C[k + 1];
  memset(C, 0, sizeof(C));

  C[0] = 1; // nC0 is 1

  for (ll int i = 1; i <= n; i++) {
    // Compute next row of pascal triangle using
    // the previous row
    for (int j = min(i, k); j > 0; j--)
      C[j] = C[j] + C[j - 1];
  }
  return C[k];
}
vector<int> pr;
bool prime[10000000];
void Sieve(ll int n) {
  memset(prime, true, sizeof(prime));
  prime[1] = false;

  for (int p = 2; p * p <= n; p++) {
    if (prime[p] == true) {
      pr.push_back(p);
      for (int i = p * p; i <= n; i += p)
        prime[i] = false;
    }
  }
}

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

// Function to find gcd of array of
// numbers
int find(int arr[], int n) {
  int result = arr[0];
  for (int i = 1; i < n; i++) {
    result = gcd(arr[i], result);

    if (result == 1) {
      return 1;
    }
  }
  return result;
}

// It reurns Fn,Fn+1
pair<int, int> fib(int n) {
  if (n == 0)
    return {0, 1};

  auto p = fib(n >> 1);
  int c = p.first * (2 * p.second - p.first);
  int d = p.first * p.first + p.second * p.second;
  if (n & 1)
    return {d, c + d};
  else
    return {c, d};
}
void reverse(string &str) {
  int n = str.length();

  // Swap character starting from two
  // corners
  for (int i = 0; i < n / 2; i++)
    swap(str[i], str[n - i - 1]);
}

string fun(string s) {
  for (int i = 0; i < s.length(); i++) {
    if (s[i] == 'O' || s[i] == 'o') {
      s[i] = '0';
    } else if (s[i] == 'l' || s[i] == 'I' || s[i] == 'L' || s[i] == 'i') {
      s[i] = '1';
    } else if (isupper(s[i])) {
      s[i] = tolower(s[i]);
    }
  }
  return s;
}

int main() {
  ios;
  ll int n;
  cin >> n;
  map<int, int> mp;
  for (int i = 1; i <= 10000; i++) {
    for (int j = 1; j <= 100; j++) {
      for (int k = 1; k <= 100; k++) {
        ll int p = (i * i) + (j * j) + (k * k) + (i * j) + (j * k) + (i * k);
        if (i == j && j == k) {
          mp[p] = 1;
        } else if (i == j || j == k || k == i) {
          mp[p] = 3;
        } else {
          mp[p] = 6;
        }
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    cout << mp[i] << endl;
  }
}