Problem p03241 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define what_is(x) cerr << #x << " is " << x << endl;
#define MT make_tuple
#define eb emplace_back
#define rep(i, begin, end)                                                     \
  for (__typeof(end) i = (begin) - ((begin) > (end));                          \
       i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

#define REP(i, a, b) for (int i = a; i <= b; i++)
#define FOR(i, n) for (int i = 0; i < n; i++)
#define error(args...)                                                         \
  {                                                                            \
    string _s = #args;                                                         \
    replace(_s.begin(), _s.end(), ',', ' ');                                   \
    stringstream _ss(_s);                                                      \
    istream_iterator<string> _it(_ss);                                         \
    err(_it, args);                                                            \
  }

void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << endl;
  err(++it, args...);
}
clock_t startTime;
long double getTime() {
  return (long double)(clock() - startTime) / CLOCKS_PER_SEC;
}

int main() {
  startTime = clock();
  ll n, m;
  cin >> n >> m;
  std::vector<ll> div;
  for (ll i = 1; i < sqrt(m) + 1; i++) {
    if (m % i == 0)
      div.eb(i);
  }
  for (auto x : div) {
    div.eb(m / x);
  }
  ll j = div.size() - 1;
  while (j >= 0 && div[j] * n > m)
    j--;
  cout << div[j];

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define what_is(x) cerr << #x << " is " << x << endl;
#define MT make_tuple
#define eb emplace_back
#define rep(i, begin, end)                                                     \
  for (__typeof(end) i = (begin) - ((begin) > (end));                          \
       i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

#define REP(i, a, b) for (int i = a; i <= b; i++)
#define FOR(i, n) for (int i = 0; i < n; i++)
#define error(args...)                                                         \
  {                                                                            \
    string _s = #args;                                                         \
    replace(_s.begin(), _s.end(), ',', ' ');                                   \
    stringstream _ss(_s);                                                      \
    istream_iterator<string> _it(_ss);                                         \
    err(_it, args);                                                            \
  }

void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << endl;
  err(++it, args...);
}
clock_t startTime;
long double getTime() {
  return (long double)(clock() - startTime) / CLOCKS_PER_SEC;
}

int main() {
  startTime = clock();
  ll n, m;
  cin >> n >> m;
  std::vector<ll> div;
  for (ll i = 1; i < sqrt(m) + 1; i++) {
    if (m % i == 0)
      div.eb(i);
  }
  for (ll k = div.size() - 1; k >= 0; k--) {
    div.eb(m / div[k]);
  }
  ll j = div.size() - 1;
  while (j >= 0 && div[j] * n > m)
    j--;
  cout << div[j];

  return 0;
}