Problem p02819 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define REP(i, n)                                                              \
  for (long long(i) = 0, i_bound = (long long)(n); (i) < i_bound; ++i)
#define FOR(i, a, b) for (long long(i) = (a); (i) < (b); ++i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
template <class T1, class T2> ostream &operator<<(ostream &s, pair<T1, T2> P) {
  return s << '<' << P.first << ", " << P.second << '>';
}
template <class T> ostream &operator<<(ostream &s, vector<T> P) {
  for (int i = 0; i < P.size(); ++i) {
    if (i > 0) {
      s << " ";
    }
    s << P[i];
  }
  return s;
}
template <class T> ostream &operator<<(ostream &s, vector<vector<T>> P) {
  for (int i = 0; i < P.size(); ++i) {
    s << endl << P[i];
  }
  return s << endl;
}
const long long MOD = static_cast<long long>(1e9) + 7LL;
const long long INF = 1234567891234567890LL;
int main() {
  cin.tie(0);
  cout.sync_with_stdio(false);
  ll X;
  cin >> X;
  ll Y = X + 3000;
  vector<int> furui(Y, 1);
  for (int i = 2; i * i <= Y; i++) {
    if (!furui[i])
      continue;
    for (int j = 2; i * j <= Y; j++) {
      furui[i * j] = 0;
    }
  }
  ll res = -1;
  for (int i = X; i <= Y; i++) {
    if (furui[i]) {
      res = i;
      break;
    }
  }
  cout << res << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define REP(i, n)                                                              \
  for (long long(i) = 0, i_bound = (long long)(n); (i) < i_bound; ++i)
#define FOR(i, a, b) for (long long(i) = (a); (i) < (b); ++i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
template <class T1, class T2> ostream &operator<<(ostream &s, pair<T1, T2> P) {
  return s << '<' << P.first << ", " << P.second << '>';
}
template <class T> ostream &operator<<(ostream &s, vector<T> P) {
  for (int i = 0; i < P.size(); ++i) {
    if (i > 0) {
      s << " ";
    }
    s << P[i];
  }
  return s;
}
template <class T> ostream &operator<<(ostream &s, vector<vector<T>> P) {
  for (int i = 0; i < P.size(); ++i) {
    s << endl << P[i];
  }
  return s << endl;
}
const long long MOD = static_cast<long long>(1e9) + 7LL;
const long long INF = 1234567891234567890LL;
int main() {
  cin.tie(0);
  cout.sync_with_stdio(false);
  ll X;
  cin >> X;
  ll Y = X + 3000;
  vector<int> furui(Y + 10, 1);
  for (int i = 2; i * i <= Y; i++) {
    if (!furui[i])
      continue;
    for (int j = 2; i * j <= Y; j++) {
      furui[i * j] = 0;
    }
  }
  ll res = -1;
  for (int i = X; i <= Y; i++) {
    if (furui[i]) {
      res = i;
      break;
    }
  }
  cout << res << endl;
  return 0;
}