Problem p03048 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define fastio()                                                               \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define loop(i, a, b) for (int i = a; i < b; i++)
#define test()                                                                 \
  int t;                                                                       \
  cin >> t;                                                                    \
  loop(test, 1, t + 1)
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define nl cout << "\n"
#define sp cout << " "
#define F first
#define S second
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vii vector<pii>
#define vll vector<pll>
#define prsp(v)                                                                \
  loop(i, 0, v.size()) cout << v[i], sp;                                       \
  nl;
#define prpsp(v)                                                               \
  loop(i, 0, v.size()) cout << v[i].F << " " << v[i].S << " , ";               \
  nl;
#define prnl(v)                                                                \
  loop(i, 0, v.size()) cout << v[i], nl;                                       \
  nl;
#define prpnl(v)                                                               \
  loop(i, 0, v.size()) cout << v[i].F << " " << v[i].S, nl;                    \
  nl;
#define MOD 1000000007
#define mod(n) (((n % MOD) + MOD) % MOD)
#define all(x) x.begin(), x.end()

const int N = 1e5 + 5;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

ll c2(ll n) {
  ll ans = n * (n - 1);
  ans /= 2;
  return ans;
}

int main() {
  fastio();

  ll r, g, b, n;
  cin >> r >> g >> b >> n;

  ll ans = 0;
  loop(i, 0, n / r + 1) {
    ll rem = n - r * i;
    loop(j, 0, rem / g + 1) {
      ll remm = rem - j * g;
      loop(k, 0, remm / b + 1) {
        ll remmm = remm - k * b;
        if (remmm == 0)
          ans++;
      }
    }
  }
  cout << ans, nl;

  cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define fastio()                                                               \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define loop(i, a, b) for (int i = a; i < b; i++)
#define test()                                                                 \
  int t;                                                                       \
  cin >> t;                                                                    \
  loop(test, 1, t + 1)
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define nl cout << "\n"
#define sp cout << " "
#define F first
#define S second
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vii vector<pii>
#define vll vector<pll>
#define prsp(v)                                                                \
  loop(i, 0, v.size()) cout << v[i], sp;                                       \
  nl;
#define prpsp(v)                                                               \
  loop(i, 0, v.size()) cout << v[i].F << " " << v[i].S << " , ";               \
  nl;
#define prnl(v)                                                                \
  loop(i, 0, v.size()) cout << v[i], nl;                                       \
  nl;
#define prpnl(v)                                                               \
  loop(i, 0, v.size()) cout << v[i].F << " " << v[i].S, nl;                    \
  nl;
#define MOD 1000000007
#define mod(n) (((n % MOD) + MOD) % MOD)
#define all(x) x.begin(), x.end()

const int N = 1e5 + 5;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

ll c2(ll n) {
  ll ans = n * (n - 1);
  ans /= 2;
  return ans;
}

int main() {
  fastio();

  ll r, g, b, n;
  cin >> r >> g >> b >> n;

  ll ans = 0;
  loop(i, 0, n / r + 1) {
    ll rem = n - r * i;
    loop(j, 0, rem / g + 1) {
      ll remm = rem - j * g;
      if (remm % b == 0)
        ans++;
    }
  }
  cout << ans, nl;

  cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
  return 0;
}