Problem p02983 (C++)

Buggy submission (status: Time Limit Exceeded):
#include "bits/stdc++.h"

#define MOD 1000000007
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define ALL(v) v.begin(), v.end()
#define FOR(i, j, k) for (ll i = j; i < k; i++)
#define DUMP(i, v)                                                             \
  for (ll i = 0; i < v.size(); i++)                                            \
  cout << v[i] << " "

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
struct Edge {
  ll from, to, cost;
};
struct node {
  ll cost, to;
  bool friend operator>(node a, node b) { return a.cost > b.cost; }
};

ll mod(ll a, ll mod) {
  ll res = a % mod;
  if (res < 0)
    res = res + mod;
  return res;
}

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

ll modinv(ll a, ll mod) { return modpow(a, mod - 2, mod); }

ll gcd(ll a, ll b) {
  ll r = a % b;
  if (r == 0)
    return b;
  else
    return gcd(b, a % b);
}

bool is_prime(ll n) {
  ll i = 2;
  if (n == 1)
    return false;
  if (n == 2)
    return true;
  bool res = true;
  while (i * i < n) {
    if (n % i == 0) {
      res = false;
    }
    i = i + 1;
  }

  // if(i==1)res = false;
  if (n % i == 0)
    res = false;
  return res;
}

/**************************************
** A main function starts from here  **
***************************************/
int main() {
  ll L, R;
  cin >> L >> R;
  if (L - R >= 2019) {
    cout << 0;
  } else {
    ll ans = 100000;
    for (ll i = L; i < R; i++) {
      for (ll j = i + 1; j <= R; j++) {
        ans = min(ans, (i * j) % 2019);
      }
    }
    cout << ans;
  }

  return 0;
}


Fixed submission:
#include "bits/stdc++.h"

#define MOD 1000000007
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define ALL(v) v.begin(), v.end()
#define FOR(i, j, k) for (ll i = j; i < k; i++)
#define DUMP(i, v)                                                             \
  for (ll i = 0; i < v.size(); i++)                                            \
  cout << v[i] << " "

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
struct Edge {
  ll from, to, cost;
};
struct node {
  ll cost, to;
  bool friend operator>(node a, node b) { return a.cost > b.cost; }
};

ll mod(ll a, ll mod) {
  ll res = a % mod;
  if (res < 0)
    res = res + mod;
  return res;
}

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

ll modinv(ll a, ll mod) { return modpow(a, mod - 2, mod); }

ll gcd(ll a, ll b) {
  ll r = a % b;
  if (r == 0)
    return b;
  else
    return gcd(b, a % b);
}

bool is_prime(ll n) {
  ll i = 2;
  if (n == 1)
    return false;
  if (n == 2)
    return true;
  bool res = true;
  while (i * i < n) {
    if (n % i == 0) {
      res = false;
    }
    i = i + 1;
  }

  // if(i==1)res = false;
  if (n % i == 0)
    res = false;
  return res;
}

/**************************************
** A main function starts from here  **
***************************************/
int main() {
  ll L, R;
  cin >> L >> R;
  if (R - L >= 2019) {
    cout << 0;
  } else {
    ll ans = 100000;
    for (ll i = L; i < R; i++) {
      for (ll j = i + 1; j <= R; j++) {
        ans = min(ans, (i * j) % 2019);
      }
    }
    cout << ans;
  }

  return 0;
}