alexjercan/bugnet huggingface dataset:
Problem p01268 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#include <stdint.h>

typedef uint32_t u32;
typedef uint64_t u64;

class Solver {
public:
  Solver();
  void solve(int N, int P);

private:
  bool isprime[200000];
};

Solver::Solver() {
  for (int i = 0; i < 200000; ++i) {
    isprime[i] = true;
  }
  isprime[0] = isprime[1] = false;
  for (int i = 2; i < 2000; ++i) {
    if (isprime[i]) {
      for (int j = i * 2; j < 200000; j += i) {
        isprime[j] = false;
      }
    }
  }
}

void Solver::solve(int N, int P) {
  std::vector<int> can;
  for (int i = N + 1; i < std::min(N + P * 4 + 1000, 200000); ++i) {
    if (not isprime[i])
      continue;
    for (int j = i; j < std::min(N + P * 4 + 1000, 200000); ++j) {
      if (not isprime[j])
        continue;
      can.push_back(i + j);
    }
  }
  std::sort(std::begin(can), std::end(can));
  std::cout << can[P - 1] << std::endl;
}

int main() {

  Solver solver;

  for (;;) {
    int N, P;
    std::cin >> N >> P;
    if (N == -1 and P == -1)
      break;

    solver.solve(N, P);
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <stdint.h>

typedef uint32_t u32;
typedef uint64_t u64;

class Solver {
public:
  Solver();
  void solve(int N, int P);

private:
  bool isprime[200000];
};

Solver::Solver() {
  for (int i = 0; i < 200000; ++i) {
    isprime[i] = true;
  }
  isprime[0] = isprime[1] = false;
  for (int i = 2; i < 2000; ++i) {
    if (isprime[i]) {
      for (int j = i * 2; j < 200000; j += i) {
        isprime[j] = false;
      }
    }
  }
}

void Solver::solve(int N, int P) {
  std::vector<int> can;
  for (int i = N + 1; i < std::min(N + P * 4 + 1000, 200000); ++i) {
    if (not isprime[i])
      continue;
    for (int j = i; j < std::min(N + P * 4 + 1000, 200000); ++j) {
      if (not isprime[j])
        continue;
      can.push_back(i + j);
    }
  }
  std::sort(std::begin(can), std::end(can));
  std::cout << can[P - 1] << std::endl;
}

int main() {

  Solver solver;

  for (;;) {
    int N, P;
    std::cin >> N >> P;
    if (N == 0 and P == 0)
      break;

    solver.solve(N, P);
  }

  return 0;
}
Problem p01268 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>

#define MAX 10000000
using namespace std;

int prime[MAX];

bool is_Prime[MAX];

int ans[1010];

int main() {

  for (int i = 2; i < MAX; i++) {
    is_Prime[i] = true;
  }

  for (int i = 2; i < MAX; i++) {
    if (is_Prime[i]) {
      for (int j = 2; i * j < MAX; j++)
        is_Prime[i * j] = false;
    }
  }

  for (int i = 2, j = 0; i < MAX; i++) {
    if (is_Prime[i]) {
      prime[j] = i;
      j++;
    }
  }

  for (int i = 0; i < 100; i++) {
    //  cout << prime[i] << " ";
  }

  int N, P;

  while (1) {
    cin >> N >> P;
    if (N == -1 && P == -1)
      break;

    int i;
    for (i = 0; prime[i] <= N; i++) {
    }
    // prime[i]
    // テ」ツ?ッNテ」ツつ暗」ツつ甘・ツ、ツァテ」ツ?催」ツ??、ツクツ?ァツ閉ェテ・ツーツ湘」ツ?陛」ツ?ェテァツエツ?ヲツ閉ー
    // cout << i << " " ;

    int t, s, x = 0;

    for (int k = i, t = 0; t < 40; t++, k++) {
      for (int l = k, s = k - i; s < 40; s++, l++) {
        ans[x] = prime[k] + prime[l];
        //		cout << ans[x] << " ";
        x++;
      }
      //     cout << endl;
    }

    sort(ans, ans + 500);

    for (i = 0; i < 100; i++) {
      //    cout << ans[i] << " ";
    }
    //    cout << endl;
    cout << ans[P - 1] << endl;
  }

  return 0;
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>

using namespace std;

int prime[100000000];

bool is_Prime[100000000];

int ans[1010];

int main() {

  for (int i = 2; i < 100000000; i++) {
    is_Prime[i] = true;
  }

  for (int i = 2; i < 100000000; i++) {
    if (is_Prime[i]) {
      for (int j = 2; i * j < 100000000; j++)
        is_Prime[i * j] = false;
    }
  }

  for (int i = 2, j = 0; i < 100000000; i++) {
    if (is_Prime[i]) {
      prime[j] = i;
      j++;
    }
  }

  for (int i = 0; i < 100; i++) {
    //  cout << prime[i] << " ";
  }

  int N, P;

  while (1) {
    cin >> N >> P;
    if (N == -1 && P == -1)
      break;

    int i;
    for (i = 0; prime[i] <= N; i++) {
    }
    // prime[i]
    // テ」ツ?ッNテ」ツつ暗」ツつ甘・ツ、ツァテ」ツ?催」ツ??、ツクツ?ァツ閉ェテ・ツーツ湘」ツ?陛」ツ?ェテァツエツ?ヲツ閉ー
    // cout << i << " " ;

    int t, s, x = 0;

    for (int k = i, t = 0; t < 40; t++, k++) {
      for (int l = k, s = k - i; s < 40; s++, l++) {
        ans[x] = prime[k] + prime[l];
        //		cout << ans[x] << " ";
        x++;
      }
      //     cout << endl;
    }

    sort(ans, ans + 500);

    for (i = 0; i < 100; i++) {
      //    cout << ans[i] << " ";
    }
    //    cout << endl;
    cout << ans[P - 1] << endl;
  }

  return 0;
}
Problem p01268 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
long long m[100], c[10000], prime[200];
int main() {
  long long n, p;
  int count = 0, i = 2;
  while (true) {
    bool t = true;
    for (int j = 2; j * j <= i; j++) {
      if (i % j == 0)
        t = false;
    }
    if (t == true) {
      prime[count] = i;
      count++;
    }
    if (count == 200)
      break;
    i++;
  }
  while (true) {
    cin >> n >> p;
    if (n == -1 && p == -1)
      break;
    for (int i = 0; i < p * p; i++) {
      c[i] = 1000000;
    }
    if (n == 0)
      n++;
    int i = n + 1, count = 0;
    while (true) {
      bool t = true;
      for (int j = 0; j < 200; j++) {
        if (i != prime[j] && i % prime[j] == 0)
          t = false;
      }
      if (t == true) {
        m[count] = i;
        count++;
      }
      if (count == p)
        break;
      if (i % 2 == 1)
        i += 2;
      else
        i++;
    }
    for (int i = 0; i < p; i++) {
      for (int j = 0; j <= i; j++) {
        c[i * p + j] = m[i] + m[j];
      }
    }
    sort(c, c + p * p);
    cout << c[p - 1] << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>
using namespace std;
long long m[100], c[10000], prime[200];
int main() {
  long long n, p;
  int count = 0, i = 2;
  while (true) {
    bool t = true;
    for (int j = 2; j * j <= i; j++) {
      if (i % j == 0)
        t = false;
    }
    if (t == true) {
      prime[count] = i;
      count++;
    }
    if (count == 200)
      break;
    i++;
  }
  while (true) {
    cin >> n >> p;
    if (n == -1 && p == -1)
      break;
    for (int i = 0; i < p * p; i++) {
      c[i] = 1000000;
    }
    if (n == 0)
      n++;
    int i = n + 1, count = 0;
    while (true) {
      bool t = true;
      for (int j = 0; j < 200; j++) {
        if (i != prime[j] && i % prime[j] == 0)
          t = false;
      }
      if (t == true) {
        m[count] = i;
        count++;
      }
      if (count == p)
        break;
      if (i % 2 == 1)
        i += 2;
      else
        i++;
    }
    for (int i = 0; i < p; i++) {
      for (int j = 0; j <= i; j++) {
        c[i * p + j] = m[i] + m[j];
      }
    }
    for (int i = 0; i < p * p - 1; i++) {
      for (int j = p * p - 1; j > i; j--) {
        if (c[j] < c[j - 1]) {
          int tmp = c[j];
          c[j] = c[j - 1];
          c[j - 1] = tmp;
        }
      }
    }
    cout << c[p - 1] << endl;
  }
  return 0;
}
Problem p01268 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;
static vector<int> primeNum;
vector<int> setPrime(long N) {
  vector<int> v;
  v.push_back(2);
  for (long i = 3; i <= 1000000; i++) {
    bool flag = false;
    for (long j = 2; j * j <= i; j++) {
      if (i % j == 0) {
        flag = true;
        break;
      }
    }

    if (!flag) {
      v.push_back(i);
    }
  }

  return v;
}
int main() {
  int N, P;
  primeNum = setPrime(1000000);
  while (cin >> N >> P && N != -1 && P != -1) {
    vector<int> primeSum;
    int index = 0;
    while (primeNum.at(index) <= N) {
      index++;
    }
    for (int i = index; i < index + P; i++) {
      for (int j = i; j < index + P; j++) {
        primeSum.push_back(primeNum.at(i) + primeNum.at(j));
      }
    }
    sort(primeSum.begin(), primeSum.end());
    cout << primeSum.at(P - 1) << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

vector<int> setPrime(int N) {
  vector<int> v;
  if (N < 2) {
    v.push_back(2);
    N = 2;
  }
  for (int i = N + 1; i <= 1000000; i++) {
    bool flag = false;
    for (int j = 2; j * j <= i; j++) {
      if (i % j == 0) {
        flag = true;
        break;
      }
    }

    if (!flag) {
      v.push_back(i);
    }
  }

  return v;
}
int main() {
  int N, P;
  while (cin >> N >> P && N != -1 && P != -1) {
    vector<int> primeNum;
    primeNum = setPrime(N);
    vector<int> primeSum;
    for (int i = 0; i < P; i++) {
      for (int j = i; j < P; j++) {
        primeSum.push_back(primeNum.at(i) + primeNum.at(j));
      }
    }
    sort(primeSum.begin(), primeSum.end());
    cout << primeSum.at(P - 1) << endl;
  }
  return 0;
}
Problem p01268 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int(i) = (0); (i) < (int)(n); ++(i))
using ll = long long;

const int MAX_N = 1000000;

int prime[MAX_N];
bool is_prime[MAX_N + 1];

void eratos(int n) {
  int p = 0;
  for (int i = 0; i <= n; ++i)
    is_prime[i] = true;
  is_prime[0] = is_prime[1] = false;
  for (int i = 2; i <= n; ++i) {
    if (is_prime[i]) {
      prime[p++] = i;
      for (int j = 2 * i; j <= n; j += i)
        is_prime[j] = false;
    }
  }
}

int main() {
  eratos(MAX_N);

  int N, P;

  while (cin >> N >> P, (N != -1 and P != -1)) {
    vector<int> t(110);
    int cnt = 0;

    for (int i = N + 1; i < MAX_N; ++i) {
      if (is_prime[i])
        t[cnt++] = i;
      if (cnt >= 105)
        break;
    }

    vector<int> tt;

    cnt = 0;
    rep(i, 101) {
      for (int j = i; j <= 100; ++j) {
        tt.push_back(t[i] + t[j]);
      }
    }

    sort(tt.begin(), tt.end());

    cout << tt[P - 1] << endl;
  }
}

Error: -6
malloc(): corrupted top size


Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int(i) = (0); (i) < (int)(n); ++(i))
using ll = long long;

const int MAX_N = 1000000;

int prime[MAX_N];
bool is_prime[MAX_N + 1];

void eratos(int n) {
  int p = 0;
  for (int i = 0; i <= n; ++i)
    is_prime[i] = true;
  is_prime[0] = is_prime[1] = false;
  for (int i = 2; i <= n; ++i) {
    if (is_prime[i]) {
      prime[p++] = i;
      for (int j = 2 * i; j <= n; j += i)
        is_prime[j] = false;
    }
  }
}

int main() {
  eratos(MAX_N);

  int N, P;

  while (cin >> N >> P, (N != -1 and P != -1)) {
    vector<int> t(100);
    int cnt = 0;

    for (int i = N + 1; i < MAX_N; ++i) {
      if (is_prime[i]) {
        t[cnt++] = i;
      }
      if (cnt >= 100)
        break;
    }

    vector<int> tt(1000);
    cnt = 0;
    rep(i, 100) {
      for (int j = i; j < 100; ++j) {
        tt[cnt++] = t[i] + t[j];
      }
    }

    sort(tt.begin(), tt.end());

    cout << tt[P - 1] << endl;
  }
}
Problem p01268 (C++) — buggy submission, verdict: Time Limit Exceeded

// Name: Matsuzaki Number
// Level: 2
// Category: 素数
// Note:

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

const int MAX_PRIME = 200000;
vector<int> primes;
bool is_prime[MAX_PRIME + 1];

void init() {
  fill_n(is_prime, MAX_PRIME + 1, true);
  is_prime[0] = is_prime[1] = false;
  for (int i = 2; i <= MAX_PRIME; ++i) {
    if (is_prime[i]) {
      primes.push_back(i);
      for (long long j = (long long)i * i; j <= MAX_PRIME; j += i) {
        is_prime[j] = false;
      }
    }
  }
}

bool solve() {
  int N, P;
  cin >> N >> P;
  if (N == -1 && P == -1)
    return false;

  vector<int>::iterator first = upper_bound(primes.begin(), primes.end(), N);
  vector<int> nums;
  const int start = distance(primes.begin(), first);
  for (int i = start; i < start + 100; ++i) {
    for (int j = i; j < start + 100; ++j) {
      nums.push_back(primes[i] + primes[j]);
    }
  }
  sort(nums.begin(), nums.end());
  cout << nums[P - 1] << endl;
  return true;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);

  init();
  for (int case_num = 1; solve(); ++case_num)
    ;
  return 0;
}

Error: TLE

Fixed submission:

// Name: Matsuzaki Number
// Level: 2
// Category: 素数
// Note:

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

const int MAX_PRIME = 200000;
vector<int> primes;
bool is_prime[MAX_PRIME + 1];

void init() {
  fill_n(is_prime, MAX_PRIME + 1, true);
  is_prime[0] = is_prime[1] = false;
  for (int i = 2; i <= MAX_PRIME; ++i) {
    if (is_prime[i]) {
      primes.push_back(i);
      for (long long j = (long long)i * i; j <= MAX_PRIME; j += i) {
        is_prime[j] = false;
      }
    }
  }
}

bool solve() {
  int N, P;
  cin >> N >> P;
  if (!N && !P)
    return false;

  vector<int>::iterator first = upper_bound(primes.begin(), primes.end(), N);
  vector<int> nums;
  const int start = distance(primes.begin(), first);
  for (int i = start; i < start + 100; ++i) {
    for (int j = i; j < start + 100; ++j) {
      nums.push_back(primes[i] + primes[j]);
    }
  }
  sort(nums.begin(), nums.end());
  cout << nums[P - 1] << endl;
  return true;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);

  init();
  for (int case_num = 1; solve(); ++case_num)
    ;
  return 0;
}
Problem p01268 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = (1LL << 31) - 1;
const ll MOD = 1e9 + 7;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, N) for (int i = 0; i < (N); i++)
#define ALL(s) (s).begin(), (s).end()
#define EQ(a, b) (abs((a) - (b)) < EPS)
#define EQV(a, b) (EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()))
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1
#define MAX_N 100100 * 3

bool is_prime[200100];
int prime[200100];

void sieve(int n) {
  int p = 0;
  fill(is_prime, is_prime + 200100, 1);
  is_prime[0] = 0;
  is_prime[1] = 0;
  for (int i = 2; i < n; i++) {
    if (is_prime[i] == 1) {
      prime[p] = i;
      p++;
      for (int j = 2 * i; j < n; j += i) {
        is_prime[j] = 0;
      }
    }
  }
}

ll n, p;

int main() {
  sieve(200000);
  while (cin >> n >> p && n + p != -2) {
    ll now = 0;
    REP(i, 200100) {
      if (prime[i] > n) {
        now = i;
        break;
      }
    }
    vector<ll> vp;
    // cout << now << " " << now + p << endl;
    FOR(i, now, now + p + 1) {
      FOR(j, i, now + p + 1) { vp.push_back(prime[i] + prime[j]); }
    }
    sort(ALL(vp));
    // REP(i, vp.size()) {
    //	cout << vp[i] << endl;
    // }
    cout << vp[p - 1] << endl;
  }
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define FOR(i, a, b) for (long long i = (a); i < (b); i++)
#define REP(i, N) for (long long i = 0; i < (N); i++)
#define ALL(s) (s).begin(), (s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 10e15 + 9
#define EPS 1e-10
#define MAX_N 100100
#define MAX_M 100100

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

int n, p;

bool is_prime[1000000];
int prime[1000000];
int field[10000][10000];

int main() {
  fill(is_prime, is_prime + 1000000, 1);
  is_prime[0] = 0;
  is_prime[1] = 0;
  int po = 0;
  for (int i = 0; i <= 101000; i++) {
    if (is_prime[i]) {
      prime[po++] = i;
      for (int j = 0; j <= 101000; j += i) {
        is_prime[j] = 0;
      }
    }
  }
  while (cin >> n >> p && n != -1 && p != -1) {
    REP(i, po) REP(j, po) field[i][j] = 1000;
    int ans = 0;
    REP(i, po) {
      REP(j, po) {}
    }
    cout << ans << endl;
  }
}
Problem p01268 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define INF 999999999
#define mod 1000000007

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = (n); i >= 0; i--)
#define REP(i, a, b) for (int i = (a); i < int(b); i++)
#define all(x) (x).begin(), x.end()
#define pb push_back
#define MOD(x) (x % (mod))
using namespace std;

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

/*---------------------------------------------------*/

int prime[150000];
bool is_prime[150000];
vector<ll> v;

void sieve() {
  int p = 0;
  rep(i, 150000) is_prime[i] = true;
  is_prime[0] = is_prime[1] = false;
  REP(i, 2, 150000) {
    if (is_prime[i]) {
      prime[p++] = i;
      for (int j = 2 * i; j < 150000; j += i)
        is_prime[j] = false;
    }
  }
  // rep(i,50)cout<<"DEBUG "<<prime[i]<<endl;
}

void solve(int n, int p) {
  ll data[11000];
  int x = 0;
  while (prime[x] <= n) {
    // cout<<x<<" "<<prime[x]<<endl;
    x++;
  }
  int cnt = 0;
  REP(i, x, x + p) {
    REP(j, i, x + p) {
      data[cnt] = (prime[i] + prime[j]);
      cnt++;
    }
  }
  sort(data, data + cnt);
  // rep(i,p)cout<<i+1<<" "<<v[i]<<endl;
  cout << data[p - 1] << endl;
}

int main() {
  int n, p;
  sieve();
  while (cin >> n >> p) {
    if (n == -1 && p == -1)
      break;
    solve(n, p);
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define INF 999999999
#define mod 1000000007

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = (n); i >= 0; i--)
#define REP(i, a, b) for (int i = (a); i < int(b); i++)
#define all(x) (x).begin(), x.end()
#define pb push_back
#define MOD(x) (x % (mod))
using namespace std;

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

/*---------------------------------------------------*/
int prime[13000];
bool is_prime[150000];
vi v;

void sieve() {
  int p = 0;
  rep(i, 150000) is_prime[i] = true;
  is_prime[0] = is_prime[1] = false;
  REP(i, 2, 150000) {
    if (is_prime[i]) {
      prime[p++] = i;
      for (int j = 2 * i; j < 150000; j += i)
        is_prime[j] = false;
    }
  }
  // rep(i,50)cout<<"DEBUG "<<prime[i]<<endl;
}

void solve(int n, int p) {
  v.clear();
  int x = 0;
  while (prime[x] <= n) {
    // cout<<x<<" "<<prime[x]<<endl;
    x++;
  }

  REP(i, x, x + p) {
    REP(j, i, x + p) { v.push_back(prime[i] + prime[j]); }
  }
  sort(all(v));
  // rep(i,p)cout<<i+1<<" "<<v[i]<<endl;
  cout << v[p - 1] << endl;
}

int main() {
  int n, p;
  sieve();
  while (cin >> n >> p) {
    if (n == -1 && p == -1)
      break;
    solve(n, p);
  }
  return 0;
}
Problem p01268 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define INF 999999999
#define mod 1000000007

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = (n); i >= 0; i--)
#define REP(i, a, b) for (int i = (a); i < int(b); i++)
#define all(x) (x).begin(), x.end()
#define pb push_back
#define MOD(x) (x % (mod))
using namespace std;

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

/*---------------------------------------------------*/

int prime[150000];
bool is_prime[150000];
vector<ll> v;

void sieve() {
  int p = 0;
  rep(i, 150000) is_prime[i] = true;
  is_prime[0] = is_prime[1] = false;
  REP(i, 2, 150000) {
    if (is_prime[i]) {
      prime[p++] = i;
      for (int j = 2 * i; j < 150000; j += i)
        is_prime[j] = false;
    }
  }
  // rep(i,50)cout<<"DEBUG "<<prime[i]<<endl;
}

void solve(int n, int p) {
  ll data[11000];
  int x = 0;
  while (prime[x] <= n) {
    // cout<<x<<" "<<prime[x]<<endl;
    x++;
  }
  int cnt = 0;
  REP(i, x, x + p) {
    REP(j, i, x + p) {
      data[cnt] = (prime[i] + prime[j]);
      cnt++;
    }
  }
  sort(data, data + cnt);
  // rep(i,p)cout<<i+1<<" "<<v[i]<<endl;
  cout << data[p - 1] << endl;
}

int main() {
  int n, p;
  sieve();
  while (cin >> n >> p) {
    if (n == -1 && p == -1)
      break;
    solve(n, p);
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define INF 999999999
#define mod 1000000007

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = (n); i >= 0; i--)
#define REP(i, a, b) for (int i = (a); i < int(b); i++)
#define all(x) (x).begin(), x.end()
#define pb push_back
#define MOD(x) (x % (mod))
using namespace std;

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

/*---------------------------------------------------*/
int prime[13000];
bool is_prime[150000];

void sieve() {
  int p = 0;
  rep(i, 150000) is_prime[i] = true;
  is_prime[0] = is_prime[1] = false;
  REP(i, 2, 150000) {
    if (is_prime[i]) {
      prime[p++] = i;
      for (int j = 2 * i; j < 150000; j += i)
        is_prime[j] = false;
    }
  }
}

void solve(int n, int p) {
  vector<ll> v;
  int x = 0;
  while (prime[x] <= n) {
    x++;
  }

  REP(i, x, x + p) {
    REP(j, i, x + p) { v.push_back(prime[i] + prime[j]); }
  }
  sort(all(v));
  cout << v[p - 1] << endl;
}

int main() {
  int n, p;
  sieve();
  while (cin >> n >> p) {
    if (n == -1 && p == -1)
      break;
    solve(n, p);
  }
  return 0;
}