Problem p03362 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <typeinfo>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i, n) for (ll i(0); (i) < (n); (i)++)
#define rep(i, n) for (ll i(0); (i) < (n); (i)++)
#define ALL(a) a.begin(), a.end()
#define elnd endl //* missspell check

//* calculate primes using sieve
ll sieve(ll n, vll &prime, vector<bool> &isprime) {
  //* return the number of primes <= n
  //* prime[0]~ prime[p-1] record the primes
  //* isprime[0] ~ isprime[n] records the sieve
  ll p = 0;
  rep(i, n + 1) isprime[i] = true;
  isprime[0] = isprime[1] = false;
  for (ll i = 2; i <= n; i++) {
    if (isprime[i]) {
      prime[p++] = i;
      for (ll j = 2 * i; j <= n; j += i)
        isprime[j] = false;
    }
  }
  return p;
}
void solve(long long N) {
  vll prime(sqrt(55555));
  vb isprime(55555 + 1, false);
  ll p = sieve(55555, prime, isprime);
  vll rec;
  REP(i, p) {
    if (prime[i] % 5 == 1)
      rec.push_back(prime[i]);
  }
  REP(i, N) { cout << rec[i] << " "; }
  cout << endl;
}

int main() {
  long long N;
  scanf("%lld", &N);
  solve(N);
  return 0;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <typeinfo>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i, n) for (ll i(0); (i) < (n); (i)++)
#define rep(i, n) for (ll i(0); (i) < (n); (i)++)
#define ALL(a) a.begin(), a.end()
#define elnd endl //* missspell check

//* calculate primes using sieve
ll sieve(ll n, vll &prime, vector<bool> &isprime) {
  //* return the number of primes <= n
  //* prime[0]~ prime[p-1] record the primes
  //* isprime[0] ~ isprime[n] records the sieve
  ll p = 0;
  rep(i, n + 1) isprime[i] = true;
  isprime[0] = isprime[1] = false;
  for (ll i = 2; i <= n; i++) {
    if (isprime[i]) {
      prime[p++] = i;
      for (ll j = 2 * i; j <= n; j += i)
        isprime[j] = false;
    }
  }
  return p;
}
void solve(long long N) {
  vll prime(55555);
  vb isprime(55555 + 1, false);
  ll p = sieve(55555, prime, isprime);
  vll rec;
  REP(i, p) {
    if (prime[i] % 5 == 1)
      rec.push_back(prime[i]);
  }
  REP(i, N) { cout << rec[i] << " "; }
  cout << endl;
}

int main() {
  long long N;
  scanf("%lld", &N);
  solve(N);
  return 0;
}