Problem:
Problem B:
Matsuzaki Number
Matsuzaki 教授は，宇宙の真理を研究している科学者である．人生，宇宙，すべての答えは 42 であると言われているが，Matsuzaki 教授はこれだけでは宇宙の真理を解明するには不十分であると考えている．Matsuzaki 教授は，宇宙の真理は 2 つのパラメータからなる関数で表されると考えており，42 はその 1 つに過ぎないというのである．
Matsuzaki 教授の定義した関数 M(
N
,
P
) は，
N
より大きい素数を 2 つ選んで（同じ数を 2 つでも構わない）和をとることで得られる数の全体を，小さいほうから順番に並べたときに，
P
番目に現れる数を表す．ここで，2 通り以上の和で表されるような数も存在するが，そういった数は和の組み合わせの数と同じ個数だけ並べられる．
例として
N
= 0 の場合を考えよう．このときは素数全体から 2 つを選んで和をとることになる．そういった和のうちで最小の数を考えると，同じ数を 2 回選ぶことも許されていることから，2 + 2 = 4 であることがわかる．すなわち M(0, 1) = 4 である．次に小さい数は 2 + 3 = 5 であるから M(0, 2) = 5 となる．同様にして考えると，和を並べたものは 4, 5, 6, 7, 8, 9, 10, 10, 12, 13, 14, 14, 16, ... のようになることがわかる．すなわち，たとえば M(0, 9) = 12 である．
同じようにして
N
= 10 の場合を考えると，このときは 10 より大きい素数 {11, 13, 17, 19, ...} から 2 つを選ぶことになり，得られる和を小さいほうから並べると 22, 24, 26, 28, 30, 30, 32, ... のようになる．
あなたの仕事は，
N
と
P
が与えられた時に M(
N
,
P
) を計算するプログラムを書くことである．
Input
入力は複数のデータセットからなる．データセットは 1 行であり，2 つの整数
N
(0 ≤
N
≤ 100,000) と
P
(1 ≤
P
≤ 100) が 1 つの空白で区切られて与えられる．
入力の終わりは，空白で区切られた 2 つの -1 を含む 1 行で示される．
Output
各データセットに対して，M(
N
,
P
) の値を 1 行に出力せよ．出力に余計な空白や改行を含めてはならない．
Sample Input
0 55
0 1
0 2
0 3
10 1
10 2
10 3
10 4
10 5
10 6
11 1
11 2
11 3
100000 100
-1 -1
Output for the Sample Input
42
4
5
6
22
24
26
28
30
30
26
30
32
200274

Submitted solutions:

code_snippet: #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int INT = 1e9;
const ll LINF = 1e18;

struct UF{
    vector<int> d;
    UF(int size):d(size,-1){}
    bool u(int x,int y){
        x = r(x); y = r(y);
        if(x != y){
            if(d[y] < d[x]) swap(x,y);
            d[x] += d[y]; d[y] = x;
        }
        return x!=y;
    }
    bool f(int x,int y){
        return r(x) == r(y);
    }
    int r(int x){
        return d[x] < 0 ? x:d[x] = r(d[x]);
    }
    int s(int x){
        return -d[r(x)];
    }
};

const ll MAX_PRIME = 200000;
vector<int> primes;
vector<int> is_prime(MAX_PRIME + 1,true);
void init_primes(){
    is_prime[0] = is_prime[1] = false;
    for(int i = 2; i <= MAX_PRIME;i++){
        if(is_prime[i]){
            primes.push_back(i);
            for(int j = i*2;j<=MAX_PRIME;j+=i) is_prime[j] = false;
        }
    }
}

void solveF(){
    init_primes();
    ll N,P;
    vector<ll> sum;
    while(cin >> N >> P){
        if(N == -1 && P == -1) break;
        sum.clear();
        auto idx = upper_bound(primes.begin(),primes.end(),N) - primes.begin();
        for(int i = 0; i <= P;i++){
            for(int j = i; j <= P;j++){
                ll S = primes[idx+i] + primes[idx+j];
                sum.push_back(S);
            }
        }
        sort(sum.begin(),sum.end());
        cout << sum[P-1] << endl;
    }
}
int main(void){
    cin.tie(0); ios_base::sync_with_stdio(false);
    solveF();
    return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 4064
final_rank: 5

code_snippet: // (⁠◕⁠ᴗ⁠◕⁠✿⁠)

// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define srep(i, s, n) for (ll i = s; i < (n); i++)
#define len(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
using namespace std;
template<typename T> using vc = vector<T>;
template<typename T> using vv = vc<vc<T>>;
template<typename T> using vvv = vv<vc<T>>;
using vi = vc<int>;using vvi = vv<int>; using vvvi = vv<vi>;
using ll = long long;using vl = vc<ll>;using vvl = vv<ll>; using vvvl = vv<vl>;
using ld = long double; using vld = vc<ld>; using vvld = vc<vld>; using vvvld = vc<vvld>;
using uint = unsigned int;
using ull = unsigned long long;
const ld pi = 3.141592653589793;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
// const ll mod = 1000000007;
const ll mod = 998244353;
inline bool inside(ll y, ll x, ll H, ll W) {return 0 <= (y) and (y) < (H) and 0 <= (x) and (x) < (W); }

#define debug(var) do { cout << #var << " :\n"; view(var); } while(0)
template<typename T>void view(const T& e) {cout << e;}
template<typename T1, typename T2>void view(const pair<T1, T2>& p) {cout << "{" << p.first << ", " << p.second << "}";}
template<typename T>void view(const vc<T>& v) {for (const auto& e : v) {view(e);cout << " ";} cout << endl;}
template<typename T>void view(const vv<T>& vv) {for (const auto& v : vv) {view(v);cout << " ";} cout << endl;}
template<typename T>void view(const set<T>& s) {for (const auto& e : s) {view(e);cout << " ";} cout << endl;}
template<typename T>void view(const unordered_set<T>& s) {for (const auto& e : s) {view(e);cout << " ";} cout << endl;}
template<typename T1, typename T2>void view(const map<T1, T2>& mp){for (const auto& e : mp) {view(e);cout << " ";} cout << endl;}


int n,p;
vector<ll> prime;


vc<bool> eratosthenes(int t){
    vc<bool> is_prime(t + 1, true);
    is_prime[0] = false; is_prime[1] = false;
    for (int i = 0; i <= t; i++){
        if (is_prime[i]){
            for (int q = i * 2; q <= t; q += i){
                is_prime[q] = false;
            }
        }
    }
    return is_prime;
}


void solve() {
    auto itr = upper_bound(all(prime),n);
    vector<ll> vv;
    rep(i,100) {
        vv.push_back(*itr);
        itr++;
    }
    vector<ll> vvv;
    rep(i,vv.size()) {
        srep(j,i,vv.size()) {
            vvv.push_back(vv[i]+vv[j]);
        }
    } 
    sort(all(vvv));
    cout << vvv[p-1] << endl;
    return;
}

int main() {

    auto v = eratosthenes(200000);
    rep(i,v.size()) {
        if (v[i]) prime.push_back(i);
    }

    while (cin >> n >> p && (n != -1 && p != -1)) {
        solve();
    }
}
accuracy: 1
time_ms: 150
memory_kb: 3712
final_rank: 7

code_snippet: #include <algorithm>
#include <bits/stdc++.h>
#include <functional>
#include <queue>
// using namespace std;

int main() {
    while (true) {
        int N, P;
        std::cin >> N >> P;

        if (N == -1 && P == -1)
            break;

        std::vector<int> primes;
        for (int i = N + 1; primes.size() < P; i++) {
            // 素数かな？

            if (i == 0 || i == 1)
                continue;

            if (i == 2) {
                primes.push_back(i);
                continue;
            }

            bool isprime = true;
            for (int k = 2; k * k <= i; k++) {
                if (i % k == 0) {
                    isprime = false;
                    break;
                }
            }

            if (isprime) {
                primes.push_back(i);
            }
        }

        std::vector<int> x;
        for (int i = 0; i < primes.size(); i++)
            for (int j = i; j < primes.size(); j++) {
                x.push_back(primes[i] + primes[j]);
            }

        std::ranges::sort(x);
        // x.erase(std::unique(x.begin(), x.end()), x.end());

        // std::cout << x.size() << std::endl;

        std::cout << x[P - 1] << std::endl;
    }
}
accuracy: 1
time_ms: 70
memory_kb: 3712
final_rank: 4

code_snippet: #include<bits/extc++.h>
#define rep(i,n) for(int i=0; i< (n); i++)
#define all(a) begin(a),end(a)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int mod = 998244353;
const int inf = (1<<30);
const ll INF = (1ull<<62);
const int dx[8] = {1,0,-1,0,1,1,-1,-1};
const int dy[8] = {0,1,0,-1,1,-1,1,-1};
template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

vector<long long> eratosthenes(){
	int MAX = 2000000;
	vector<int> e(MAX);
	for (int i = 2; i < MAX; i++){
		for (int j = i; j < MAX; j += i){
			e[j]++;
		}
	}
	vector<long long> p;
	for (int i = 2; i < MAX; i++){
		if (e[i] == 1){
			p.push_back(i);
		}
	}
	return p;
}


int main(){
    auto p = eratosthenes();
    while(1){
        int N, P;
        cin >> N >> P;
        if (N == -1) break;
        int k = upper_bound(all(p), N) - p.begin();
        vector<int> A;
        for (int i = 0; i <= P; i++){
            for (int j = i; j <= P; j++){
                A.push_back(p[k + i] + p[k + j]);
            }
        }
        sort(all(A));
        cout << A[P - 1] << endl;
    }
}
accuracy: 1
time_ms: 80
memory_kb: 13264
final_rank: 18

code_snippet: #pragma region Macros
#include <bits/stdc++.h>

using namespace std;
using lint = long long;
using ull = unsigned long long;
using ld = long double;
using int128 = __int128_t;
#define all(x) (x).begin(), (x).end()
#define EPS 1e-8
#define uniqv(v) v.erase(unique(all(v)), v.end())
#define OVERLOAD_REP(_1, _2, _3, name, ...) name
#define REP1(i, n) for (auto i = std::decay_t<decltype(n)>{}; (i) != (n); ++(i))
#define REP2(i, l, r) for (auto i = (l); (i) != (r); ++(i))
#define rep(...) OVERLOAD_REP(__VA_ARGS__, REP2, REP1)(__VA_ARGS__)
#define log(x) cout << x << endl
#define logfixed(x) cout << fixed << setprecision(10) << x << endl;
#define logy(bool)         \
  if (bool) {              \
    cout << "Yes" << endl; \
  } else {                 \
    cout << "No" << endl;  \
  }

ostream &operator<<(ostream &dest, __int128_t value) {
  ostream::sentry s(dest);
  if (s) {
    __uint128_t tmp = value < 0 ? -value : value;
    char buffer[128];
    char *d = end(buffer);
    do {
      --d;
      *d = "0123456789"[tmp % 10];
      tmp /= 10;
    } while (tmp != 0);
    if (value < 0) {
      --d;
      *d = '-';
    }
    int len = end(buffer) - d;
    if (dest.rdbuf()->sputn(d, len) != len) {
      dest.setstate(ios_base::badbit);
    }
  }
  return dest;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  for (int i = 0; i < (int)v.size(); i++) {
    os << v[i] << (i + 1 != (int)v.size() ? " " : "");
  }
  return os;
}

template <typename T>
ostream &operator<<(ostream &os, const set<T> &set_var) {
  for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
    os << *itr;
    ++itr;
    if (itr != set_var.end()) os << " ";
    itr--;
  }
  return os;
}

template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &map_var) {
  for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
    os << itr->first << " -> " << itr->second << "\n";
  }
  return os;
}

template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &pair_var) {
  os << "(" << pair_var.first << ", " << pair_var.second << ")";
  return os;
}

void out() { cout << '\n'; }
template <class T, class... Ts>
void out(const T &a, const Ts &...b) {
  cout << a;
  (cout << ... << (cout << ' ', b));
  cout << '\n';
}

template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
  for (T &in : v) is >> in;
  return is;
}

inline void in(void) { return; }
template <typename First, typename... Rest>
void in(First &first, Rest &...rest) {
  cin >> first;
  in(rest...);
  return;
}

template <typename T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

vector<lint> dx8 = {1, 1, 0, -1, -1, -1, 0, 1};
vector<lint> dy8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<lint> dx4 = {1, 0, -1, 0};
vector<lint> dy4 = {0, 1, 0, -1};

#pragma endregion

vector<bool> prime_table(int n) {
  vector<bool> prime(n + 1, true);
  if (n >= 0) prime[0] = false;
  if (n >= 1) prime[1] = false;
  for (int i = 2; i * i <= n; i++) {
    if (!prime[i]) continue;
    for (int j = i * i; j <= n; j += i) {
      prime[j] = false;
    }
  }
  return prime;
}

int main() {
  cin.tie(0)->sync_with_stdio(0);
  int n = 1e6;
  vector<bool> t = prime_table(n);

  vector<int> prime;

  rep(i, n) {
    if (t[i]) {
      prime.emplace_back(i);
    }
  }

  int m, p;
  while (1) {
    in(m, p);
    if (m == -1 and p == -1) break;

    int id = distance(prime.begin(), upper_bound(all(prime), m));

    vector<int> r;
    rep(i, 500) {
      rep(j, i, 500) {
        r.emplace_back(prime[id + i] + prime[id + j]);
      }
    }

    sort(all(r));

    out(r[p - 1]);
  }
}
accuracy: 1
time_ms: 4330
memory_kb: 4756
final_rank: 19

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;
using int128 = __int128;
using State = string::const_iterator;
class ParseError {};
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define reps(i, l, r) for(ll i = (l); i < (r); i++)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define endl "\n";
const ll INF = LLONG_MAX / 4;
const ld inf = numeric_limits<long double>::max() / (ld)4;
const ll mod1 = 1000000007;
const ll mod2 = 998244353;
const ld pi = 3.1415926535897;
const ll Hash = (1ll << 61) - 1;
ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
ll dy[8] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T>
bool chmax(T &a, const T& b) {
	if (a < b) { a = b; return true; }
	return false;
}
template <typename T>
bool chmin(T &a, const T& b) {
	if (a > b) { a = b; return true; }
	return false;
}
template <ll mod>
struct modint {
	ll x;
	modint() : x(0) {}

	modint(ll y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

	modint &operator+=(const modint &p) {
		if ((x += p.x) >= mod) {
			x -= mod;
		}
		return *this;
	}
	modint &operator-=(const modint &p) {
		if ((x += mod - p.x) >= mod) {
			x -= mod;
		}
		return *this;
	}
	modint &operator*=(const modint &p) {
		x = (ll)(1ll * x * p.x % mod);
		return *this;
	}
	modint &operator/=(const modint &p) {
		*this *= p.inverse();
		return *this;
	}

	modint operator-() const { return modint(-x); }
	modint operator+(const modint &p) const { return modint(*this) += p; }
	modint operator-(const modint &p) const { return modint(*this) -= p; }
	modint operator*(const modint &p) const { return modint(*this) *= p; }
	modint operator/(const modint &p) const { return modint(*this) /= p; }
	bool operator==(const modint &p) const { return x == p.x; }
	bool operator!=(const modint &p) const { return x != p.x; }
	friend ostream &operator<<(ostream &os, const modint &p) { return os << p.x; }
	friend istream &operator>>(istream &is, modint &a) {
		ll t; is >> t;
		a = modint<mod>(t);
		return (is);
	}

	modint inverse() const {
	    int a = x, b = mod, u = 1, v = 0, t;
		while (b > 0) {
			t = a / b;
			swap(a -= t * b, b);
			swap(u -= t * v, v);
		}
		return modint(u);
	}
	modint pow(ll n) const {
		modint ret(1), mul(x);
		while (n > 0) {
			if (n & 1) ret *= mul;
			mul *= mul;
			n >>= 1;
		}
		return ret;
	}

	static ll get_mod() { return mod; }
};
bool isprime(ll N) {
	if (N < 2) return false;
	if (N < 4) return true;
	for (ll i = 2; i * i <= N; i++) {
		if (N % i == 0) return false; 
	}
	return true;
}
void solve() {
	while (1) {
		ll N, M; cin >> N >> M;
		if (M == -1) return;
		vector<ll>A(M);
		ll pos = 0;
		while (pos < M) {
			N++;
			if (isprime(N)) {
				A[pos] = N;
				pos++;
			}
		}
		multiset<ll>S;
		rep(i, M) {
			for (ll j = i; j < M; j++) {
				S.insert(A[i] + A[j]);
			}
		}
		rep(i, M - 1) S.erase(S.begin());
		cout << *S.begin() << endl;
	}
}
int main() {
	ll T = 1;
	//cin >> T;
	while (T--) solve();
}
accuracy: 1
time_ms: 290
memory_kb: 3584
final_rank: 13

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using a2 = array<ll, 2>;
using a3 = array<ll, 3>;

template <typename A> void chmin(A &l, const A &r) {
    if(r < l)
        l = r;
}
template <typename A> void chmax(A &l, const A &r) {
    if(l < r)
        l = r;
}

ll mod = 998244353;

vector<ll> prime;
vector<char> isprime;
void init() {
    isprime = vector<char>(200000, 1);
    isprime[0] = 0;
    isprime[1] = 0;
    for(int i = 2; i < isprime.size(); i++) {
        if(isprime[i]) {
            prime.push_back(i);
            for(int j = 2 * i; j < isprime.size(); j += i) {
                isprime[j] = 0;
            }
        }
    }
}

ll n, m;
void input() { cin >> n >> m; }

void solve() {
    ll idx = upper_bound(prime.begin(), prime.end(), n) - prime.begin();

    vector<ll> v;
    for(int i = idx; i < idx + 100; i++) {
        for(int j = i; j < idx + 100; j++)
            v.push_back(prime[i] + prime[j]);
    }
    sort(v.begin(), v.end());

    cout << v[m - 1] << endl;
}

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

    init();
    while(1) {
        input();
        if(n == -1)
            break;
        solve();
    }

    return 0;
}
accuracy: 1
time_ms: 180
memory_kb: 3508
final_rank: 6

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;
using PP = pair<int, P>;
using PLL = pair<ll, ll>;
using PPLL = pair<ll, PLL>;
#define rep(i, n) for(ll i = 0; i < n; ++i)
#define rrep(i, n) for(ll i = n - 1; i >= 0; --i)
#define loop(i, a, b) for(ll i = a; i <= b; ++i)
#define all(v) v.begin(), v.end()
#define nC2(n) n * (n - 1) / 2
constexpr ll INF = 9009009009009009009LL;
constexpr int INF32 = 2002002002;
constexpr ll MOD = 998244353;
constexpr ll MOD107 = 1000000007;

// Linear Algebra ////////////////////////////////////////////////
const double Rad2Deg = 180.0 / M_PI;
const double Deg2Rad = M_PI / 180.0;
//////////////////////////////////////////////////////////////////

int dx[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int dy[8] = {1, 0, -1, 0, 1, -1, 1, -1};

template <class T>
inline bool chmax(T &a, const T &b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
template <class T>
inline bool chmin(T &a, const T &b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}

template <typename Container,
          typename = std::enable_if_t<
              !std::is_same_v<Container, std::string> &&
              std::is_convertible_v<decltype(std::declval<Container>().begin()),
                                    typename Container::iterator>>>
ostream &operator<<(ostream &os, const Container &container) {
    auto it = container.begin();
    auto end = container.end();

    if (it != end) {
        os << *it;
        ++it;
    }
	for (; it != end; ++it) {
		os << " " << *it;
	}
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    for (size_t i = 0; i < v.size(); ++i) {
        os << v[i];
        if (i != v.size() - 1) os << " ";
    }
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, const vector<vector<T>>& vv) {
	for (size_t i = 0; i < vv.size(); ++i) {
		os << vv[i];
		if (i != vv.size() - 1) os << "\n";
    }
    return os;
}
template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
	assert(v.size() > 0);
	for (size_t i = 0; i < v.size(); ++i) is >> v[i];
	return is;
}
template <typename T>
istream& operator>>(istream& is, vector<vector<T>>& vv) {
	assert(vv.size() > 0);
	for (size_t i = 0; i < vv.size(); ++i) is >> vv[i];
	return is;
}

struct phash {
	template<class T1, class T2>
    inline size_t operator()(const pair<T1, T2> & p) const {
        auto h1 = hash<T1>()(p.first);
        auto h2 = hash<T2>()(p.second);

		size_t seed = h1 + h2; 
		h1 = ((h1 >> 16) ^ h1) * 0x45d9f3b;
        h1 = ((h1 >> 16) ^ h1) * 0x45d9f3b;
        h1 = (h1 >> 16) ^ h1;
        seed ^= h1 + 0x9e3779b9 + (seed << 6) + (seed >> 2);
		h2 = ((h2 >> 16) ^ h2) * 0x45d9f3b;
        h2 = ((h2 >> 16) ^ h2) * 0x45d9f3b;
        h2 = (h2 >> 16) ^ h2;
        seed ^= h2 + 0x9e3779b9 + (seed << 6) + (seed >> 2);
        return seed;
    }
};




/**
 * @brief エラトステネスの篩 O(N log log N)
 * @param n 素数を求める範囲
 * @return vector<bool> xが素数かどうか
 */
vector<bool> sieve(const ll n) {
	vector<bool> is_prime(n + 1, true);
	is_prime[0] = is_prime[1] = false;
	for (ll i = 2; i * i <= n; ++i) {
		if (!is_prime[i]) continue;
		for (ll j = i * i; j <= n; j += i) is_prime[j] = false;
	}
	return is_prime;
}

/**
 * @brief エラトステネスの篩 O(N log log N)
 * @param n 素数を求める範囲
 * @return vector<ll> 素数のリスト
 */
vector<ll> primes(const ll n) {
	vector<bool> is_prime(n + 1, true);
	vector<ll> res;
	is_prime[0] = is_prime[1] = false;
	for (ll i = 2; i <= n; ++i) {
		if (!is_prime[i]) continue;
		res.push_back(i);
		for (ll j = i * i; j <= n; j += i) is_prime[j] = false;
	}
	return res;
}
vll prime;

int solve() {
	ll n, p;
	cin >> n >> p;
	if (n == -1 && p == -1)
		return 1;

	ll mn = 0;
	rep(i, prime.size()) {
		if (n < prime[i]) {
			mn = i;
			break;
		}
	}

	vll ans;
	loop(i, mn, min(mn + 100, (ll)prime.size() - 1)) {
		loop(j, i, min(mn + 100, (ll)prime.size() - 1)) {
			ans.push_back(prime[i] + prime[j]);
		}
	}

	sort(all(ans));

	cout << ans[p - 1] << "\n";

	return 0;
}

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

	prime = primes(1e6);
	while (!solve())
	{
	}
	return 0;
}
accuracy: 1
time_ms: 160
memory_kb: 4572
final_rank: 14

code_snippet: // AOJ 2150 - Matsuzaki Number
// JAG Practice Contest for Japan Domestic 2009 - Problem B

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

set<int> prime;

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

  auto itr = prime.upper_bound(N);
  vector<int> a(100);
  for(int i=0; i<100; ++i) {
    a[i] = *itr;
    ++itr;
  }
  vector<int> m;
  for(int i=0; i<100; ++i) {
    for(int j=i; j<100; ++j) {
      m.emplace_back(a[i] + a[j]);
    }
  }
  sort(m.begin(), m.end());
  cout << m[P-1] << endl;
  return true;
}

int main() {
  prime.insert(2);
  for(int i=3; i<=1'000'000; i+=2) prime.insert(i);
  for(int i=3; i<=1'000; i+=2) {
    for(int j=i; i*j<=1'000'000; j+=2) {
      prime.erase(i*j);
    }
  }
  while(solving()) {}
}
accuracy: 1
time_ms: 480
memory_kb: 26864
final_rank: 20

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

vector<int> Prime;

bool solve() {
    int N, P;
    cin >> N >> P;
    if (N == -1 && P == -1) return false;
    auto it = upper_bound(Prime.begin(), Prime.end(), N);
    vector<int> V;
    while (ssize(V) <= P) V.push_back(*it++);
    vector<int> S;
    for (int u : V) {
        for (int v : V) {
            if (u <= v) S.push_back(u + v);
        }
    }
    sort(S.begin(), S.end());
    cout << S[P - 1] << '\n';
    return true;
}

int main() {
    int M = 2 << 17;
    vector<bool> P(M, true);
    for (int i = 2; i < M; i++) {
        if (P[i]) {
            Prime.push_back(i);
            for (int j = i + i; j < M; j += i) P[j] = false;
        }
    }
    while (solve()) {}
}
accuracy: 1
time_ms: 50
memory_kb: 3712
final_rank: 3

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define all(...) std::begin(__VA_ARGS__), std::end(__VA_ARGS__)
#define rall(...) std::rbegin(__VA_ARGS__), std::rend(__VA_ARGS__)
#define OVERLOAD_REP(_1, _2, _3, _4, name, ...) name
#define REP1(n) for(ll i=0;i<(n);i++)
#define REP2(i, n) for (ll i=0;i<(n);i++)
#define REP3(i, a, n) for (ll i=a;i<(n);i++)
#define REP4(i, a, b, n) for(ll i=a;i<(n);i+=b)
#define rep(...) OVERLOAD_REP(__VA_ARGS__, REP4, REP3, REP2, REP1)(__VA_ARGS__)
#define OVERLOAD_RREP(_1, _2, _3, _4, name, ...) name
#define RREP1(n) for(ll i=(n)-1;i>=0;i--)
#define RREP2(i, n) for(ll i=(n)-1;i>=0;i--)
#define RREP3(i, a, n) for(ll i=(n)-1;i>=(a);i--)
#define RREP4(i, a, b, n) for(ll i=(n)-1;i>=(a);i-=(b))
#define rrep(...) OVERLOAD_RREP(__VA_ARGS__, RREP4, RREP3, RREP2, RREP1)(__VA_ARGS__)
#define uniq(a) sort(all(a));a.erase(unique(all(a)),end(a))
#define len(n) (long long)(n).size()
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using vvs = vector<vs>;
using vvvs = vector<vvs>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vvvld = vector<vvld>;
using vc = vector<char>;
using vvc = vector<vc>;
using vvvc = vector<vvc>;
using pll = pair<ll,ll>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;

ll intpow(ll a,ll b){
    ll ans = 1;
    while (b){
        if (b & 1){
            ans *= a;
        }
        a *= a;
        b /= 2;
    }
    return ans;
}
ll modpow(ll a,ll b,ll c){
    ll ans = 1;
    while (b){
        if (b & 1){
            ans *= a;
            ans %= c;
        }
        a *= a;
        a %= c;
        b /= 2;
    }
    return ans;
}

template<class... T>
void input(T&... a){
    (cin >> ... >> a);
}

#define INT(...) int __VA_ARGS__; input(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__; input(__VA_ARGS__)
#define ULL(...) ull __VA_ARGS__; input(__VA_ARGS__)
#define LD(...) ld __VA_ARGS__; input(__VA_ARGS__)
#define STR(...) string __VA_ARGS__; input(__VA_ARGS__)
#define CHA(...) char __VA_ARGS__; input(__VA_ARGS__)
#define VLL(name,length) vll name(length);rep(i,length){cin >> name[i];}
#define VVLL(name,h,w) vvll name(h,vll(w));rep(i,h)rep(j,w){cin >> name[i][j];}
#define VVVLL(name,a,b,c) vvvll name(a,vvll(b,vll(c)));rep(i,a)rep(j,b)rep(k,c){cin >> name[i][j][k];}
#define VI(name,length) vi name(length);rep(i,length){cin >> name[i];}
#define VVI(name,h,w) vvi name(h,vi(w));rep(i,h)rep(j,w){cin >> name[i][j];}
#define VVVI(name,a,b,c) vvvi name(a,vvll(b,vi(c)));rep(i,a)rep(j,b)rep(k,c){cin >> name[i][j][k];}
#define VLD(name,length) vld name(length);rep(i,length){cin >> name[i];}
#define VVLD(name,h,w) vvld name(h,vld(w));rep(i,h)rep(j,w){cin >> name[i][j];}
#define VVVLD(name,a,b,c) vvvld name(a,vvld(b,vld(c)));rep(i,a)rep(j,b)rep(k,c){cin >> name[i][j][k];}
#define VC(name,length) vc name(length);rep(i,length){cin >> name[i];}
#define VVC(name,h,w) vvc name(h,vc(w));rep(i,h)rep(j,w){cin >> name[i][j];}
#define VVVC(name,a,b,c) vvvc name(a,vvc(b,vc(c)));rep(i,a)rep(j,b)rep(k,c){cin >> name[i][j][k];}
#define VS(name,length) vs name(length);rep(i,length){cin >> name[i];}
#define VVS(name,h,w) vvs name(h,vs(w));rep(i,h)rep(j,w){cin >> name[i][j];}
#define VVVS(name,a,b,c) vvvs name(a,vvs(b,vs(c)));rep(i,a)rep(j,b)rep(k,c){cin >> name[i][j][k];}
#define PLL(name) pll name;cin>>name.first>>name.second;
#define VPLL(name,length) vpll name(length);rep(i,length){cin>>name[i].first>>name[i].second;}

void print(){cout << "\n";}

template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, const std::pair<T1, T2>& p) {
    os << "(" << p.first << ", " << p.second << ")";
    return os;
}

template <typename T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
    os << "[";
    for (size_t i = 0; i < vec.size(); ++i) {
        os << vec[i];
        if (i + 1 < vec.size()) os << ", ";
    }
    os << "]";
    return os;
}

template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, const std::vector<std::pair<T1, T2>>& a) {
    os << "[";
    for (size_t j = 0; j < a.size(); ++j) {
        os << "(" << a[j].first << ", " << a[j].second << ")";
		if (j + 1 < a.size()) os << ", ";
    }
	os << "]";
    return os;
}

template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, const std::vector<std::vector<std::pair<T1, T2>>>& mat) {
	os << "[";
    for (size_t i = 0; i < mat.size(); ++i) {
		os << "[";
        for (size_t j = 0; j < mat[i].size(); ++j) {
            os << "(" << mat[i][j].first << ", " << mat[i][j].second << ")";
			if (j + 1 < mat[i].size()) os << ", ";
        }
		os << "]";
		if (i + 1 < mat.size()) os << ", ";
    }
	os << "]";
    return os;
}

template <typename T>
std::ostream& operator<<(std::ostream& os, const std::set<T>& s) {
    os << "{";
    bool first = true;
    for (const auto& x : s) {
        if (!first) os << ", ";
        os << x;
        first = false;
    }
    os << "}";
    return os;
}

template <typename K, typename V>
std::ostream& operator<<(std::ostream& os, const std::map<K, V>& m) {
    os << "{";
    bool first = true;
    for (const auto& [key, val] : m) {
        if (!first) os << ", ";
        os << key << ": " << val;
        first = false;
    }
    os << "}";
    return os;
}

template<class T, class... Ts>
void print(const T& a, const Ts&... b){cout << a;(cout << ... << (cout << ' ', b));cout << '\n';}

void write(){cout << "\n";}
template<class T, class... Ts>
void write(const T& a, const Ts&... b){cout << a;(cout << ... << (cout << ' ', b));cout << '\n';}
void write(vll x){rep(i,len(x)){cout << x[i];if(i!=len(x)-1){cout << " ";}else{cout << '\n';}}}
void write(vvll x){rep(i,len(x))rep(j,len(x[i])){cout << x[i][j];if(j!=len(x[i])-1){cout << " ";}else{cout << '\n';}}}
void write(vi x){rep(i,len(x)){cout << x[i];if(i!=len(x)-1){cout << " ";}else{cout << '\n';}}}
void write(vvi x){rep(i,len(x))rep(j,len(x[i])){cout << x[i][j];if(j!=len(x[i])-1){cout << " ";}else{cout << '\n';}}}
void write(vvvi x){rep(i,len(x))rep(j,len(x[i]))rep(k,len(x[i][j])){cout << x[i][j][k];if(k!=len(x[i][j])-1){cout << " ";}else if(j!=len(x[i])-1){cout << " | ";}else{cout << '\n';}}}
void write(vld x){rep(i,len(x)){cout << x[i];if(i!=len(x)-1){cout << " ";}else{cout << '\n';}}}
void write(vvld x){rep(i,len(x))rep(j,len(x[i])){cout << x[i][j];if(j!=len(x[i])-1){cout << " ";}else{cout << '\n';}}}
void write(vvvld x){rep(i,len(x))rep(j,len(x[i]))rep(k,len(x[i][j])){cout << x[i][j][k];if(k!=len(x[i][j])-1){cout << " ";}else if(j!=len(x[i])-1){cout << " | ";}else{cout << '\n';}}}
void write(vc x){rep(i,len(x)){cout << x[i];if(i!=len(x)-1){cout << " ";}else{cout << '\n';}}}
void write(vvc x){rep(i,len(x))rep(j,len(x[i])){cout << x[i][j];if(j!=len(x[i])-1){cout << " ";}else{cout << '\n';}}}
void write(vvvc x){rep(i,len(x))rep(j,len(x[i]))rep(k,len(x[i][j])){cout << x[i][j][k];if(k!=len(x[i][j])-1){cout << " ";}else if(j!=len(x[i])-1){cout << " | ";}else{cout << '\n';}}}
void write(vs x){rep(i,len(x)){cout << x[i];if(i!=len(x)-1){cout << " ";}else{cout << '\n';}}}
void write(vvs x){rep(i,len(x))rep(j,len(x[i])){cout << x[i][j];if(j!=len(x[i])-1){cout << " ";}else{cout << '\n';}}}
void write(vvvs x){rep(i,len(x))rep(j,len(x[i]))rep(k,len(x[i][j])){cout << x[i][j][k];if(k!=len(x[i][j])-1){cout << " ";}else if(j!=len(x[i])-1){cout << " | ";}else{cout << '\n';}}}
void write(pll x){cout << x.first << ' ' << x.second << '\n';}
void write(vpll x){rep(i,len(x)){cout << x[i].first << ' ' << x[i].second << '\n';}}
void write(vvpll x){rep(i,len(x))rep(j,len(x[i])){cout << x[i][j].first << ' ' << x[i][j].second;if(j!=len(x[i])-1){cout << " ";}else{cout << '\n';}}}

template <typename T>
T sum(const std::vector<T>& v) {
    return std::accumulate(v.begin(), v.end(), T(0));
}

template<class T> bool chmin(T& a, const T& b){ if(a > b){ a = b; return 1; } return 0; }
template<class T> bool chmax(T& a, const T& b){ if(a < b){ a = b; return 1; } return 0; }
template<class T, class U> bool chmin(T& a, const U& b){ if(a > T(b)){ a = b; return 1; } return 0; }
template<class T, class U> bool chmax(T& a, const U& b){ if(a < T(b)){ a = b; return 1; } return 0; }

long long mod_mul(long long a, long long b, long long mod) {
    return (__int128)a * b % mod;
}

long long mod_pow(long long a, long long b, long long mod) {
    long long result = 1;
    a %= mod;
    while (b > 0) {
        if (b & 1) result = mod_mul(result, a, mod);
        a = mod_mul(a, a, mod);
        b >>= 1;
    }
    return result;
}

bool MillerRabin(ll x){
    
    if(x <= 1){return false;}
    if(x == 2){return true;}
    if((x & 1) == 0){return false;}
    vll test;
    if(x < (1 << 30)){
        test = {2, 7, 61};
    } 
    else{
        test = {2, 325, 9375, 28178, 450775, 9780504, 1795265022};
    }
    ll s = 0;
    ll d = x - 1;
    while((d & 1) == 0){
        s++;
        d >>= 1;
    }
    for(ll i:test){
        if(x <= i){return true;}
        ll y = mod_pow(i,d,x);
        if(y == 1 || y == x - 1){continue;}
        ll c = 0;
        for(int j=0;j<s-1;j++){
            y = mod_mul(y,y,x);
            if(y == x - 1){
                c = 1;
                break;
            }
        }
        if(c == 0){
            return false;
        }
    }
    return true;
}

int main(){
	ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
    while(1){
        LL(n,p);
        if(n == -1 && p == -1){break;}
        p--;
        vll a;
        rep(i,n+1,1000000000){
            if(MillerRabin(i)){
                a.push_back(i);
                if(len(a) == 100){
                    break;
                }
            }
        }
        vll b;
        rep(i,len(a)){
            rep(j,i,len(a)){
                b.push_back(a[i]+a[j]);
            }
        }
        sort(all(b));
        print(b[p]);
    }
    
}
accuracy: 1
time_ms: 250
memory_kb: 3584
final_rank: 10

code_snippet: #if __has_include(<yoniha/all.h>)
#include <yoniha/all.h>
using namespace atcoder;
#else
#include <bits/stdc++.h>
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
#endif
using namespace std;

#define int long long
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = (int)(n - 1); i >= 0; i--)
template <typename T> bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template <typename T> bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}

// using mint = modint;

signed main(){
  int pmax = 200275;
  vector isprime(pmax, true);
  isprime.at(0) = false; isprime.at(1) = false;
  vector prime(0, 0ll);
  for(int p = 2; p < pmax; p++){
    if(!isprime.at(p)) continue;
    prime.emplace_back(p);
    for(int i = 2; i * p < pmax; i++) isprime.at(i * p) = false;
  }
  
  while(true){
    int n, p; cin >> n >> p;
    if(n == -1) break;
    int idx = 0;
    while(prime.at(idx) <= n) idx++;
    vector ans(0, 0ll);
    for(int i = 0; i < p + 2 && i + idx < prime.size(); i++) for(int j = 0; j < p && i + j + idx < prime.size(); j++){
      ans.emplace_back(prime.at(i + idx) + prime.at(i + j + idx));
    }
    sort(all(ans));
    cout << ans.at(p - 1) << '\n';
  }
}
accuracy: 1
time_ms: 110
memory_kb: 3968
final_rank: 9

code_snippet: #include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <string>
#include <functional>
using namespace std;
using ll = long long;
using lb = long double;

int main() {
    vector<bool> prime(pow(10, 6), true);
    vector<int> primes;
    prime[0] = false;
    prime[1] = false;
    for (int i = 2; i < prime.size(); i++) {
        if (prime[i]) {
            primes.push_back(i);
            for (int j = 2; i*j < prime.size(); j++) prime[i*j] = false;
        }
    }

    while(true) {
        int n, p;
        cin >> n >> p;
        if (n == -1 && p == -1) return 0;
        vector<int> sumprime(0);
        for (int i = n+1; i < prime.size(); i++) {
            if (prime[i]) {n = i; break;}
        }
        auto it = find(primes.begin(), primes.end(), n);
        if (it != primes.end()) {
            size_t index = distance(primes.begin(), it);
            n = index;
        }
        
        for (int i = n; i < n+p; i++) {
            for (int j = i; j < n+p; j++) {
                sumprime.push_back(primes[i] + primes[j]);
            }
        }
        sort(sumprime.begin(), sumprime.end());
        cout << sumprime[p-1] << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 60
memory_kb: 3444
final_rank: 2

code_snippet: #include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <string> //to_string等
#include <functional>
using namespace std;
using ll = long long;
using lb = long double;

int main(){
    vector<bool>pn(pow(10,6),true);
    pn[0] = 0;
    pn[1] = 0;

    for(int i=2;i<pow(10,6);i++){
        if(pn[i]){
            for(int j=2*i;j<pow(10,6);j+=i){
                pn[j]=false;
            }
        }
    }
    while(true){
        int n,p;
        cin >> n >> p;
        if(n==-1 && p==-1){
            return 0;
        }
        vector<int>s(0);
        int j=0;
        for(int i=0;i<pn.size();i++){
            if(j<100 && pn[i] && i > n){
                s.push_back(i);
                j++;
            }
        }
        vector<int>sum(0);
        for(int i=0;i<s.size();i++){
            for(int j=i;j<s.size();j++){
                sum.push_back(s[i]+s[j]);
            }
        }
        sort(sum.begin(),sum.end());

        cout << sum[p-1] << endl;
    }
}
accuracy: 1
time_ms: 950
memory_kb: 3552
final_rank: 17

code_snippet: #include<bits/stdc++.h>
using namespace std;
int main() {
  const int max_N = 2200000;
  vector<long long> primes;
  vector<bool> isprime(max_N + 1, true);
  for (long long i = 2; i <= max_N; i++) {
    if (isprime[i]) {
      primes.push_back(i);
      for (int j = i * 2; j <= max_N; j+=i) {
        isprime[j] = false;
      }
    }
  }
  // for (int i = 0; i < 100; i++) {
  //   cout << primes[i] << '\n';
  // }
  while (1) {
    int N, P;
    cin >> N >> P;
    if (N == -1 && P == -1) {
      break;
    }
    P--;
    auto itr = upper_bound(primes.begin(), primes.end(), N);
    vector<int> List;
    for (int i = 0; i < 100; i++) {
      List.push_back(*itr);
      itr++;
    }
    vector<int> tmp;
    for (int j = 0; j < 100; j++) {
      for (int k = j; k < 100; k++) {
        tmp.push_back(List[j] + List[k]);
      } 
    }
    sort(tmp.begin(), tmp.end());
    for (int w : tmp) {
      //cout << w << '\n';
    }
    cout << tmp[P] << endl;
  }
}
accuracy: 1
time_ms: 180
memory_kb: 5232
final_rank: 16

code_snippet: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
#include <map>
using namespace std;

const int MAX_PRIME = 200000;
vector<int> primes;
vector<bool> is_prime(MAX_PRIME, true);


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


int solve(int n, int p) {
    vector<int> target_primes; //Nより大きい素数のリスト
    for(int p : primes) {
        if(p > n) {
            target_primes.push_back(p);
        }
    }

    //優先度付きキューを作成
    using T = pair<int, pair<int, int> >; //{sum, {i, j}}
    priority_queue<T, vector<T>, greater<T> > pq;

    int size = target_primes.size();
    for(int i = 0; i < size; i++) {
        pq.push({target_primes[i] + target_primes[i], {i, i}});
    }

    int count = 0;
    int answer = 0;

    while(count < p) {
        auto [sum, indices] = pq.top();
        pq.pop();
        int i = indices.first;
        int j = indices.second;

        answer = sum;
        count++;

        if(j+1 < size) {
            pq.push({target_primes[i] + target_primes[j+1], {i, j+1}});
        }
    }

    return answer;
}



int main(void) {
    sieve();

    int n, p;
    while(cin >> n >> p) {
        if(n == -1 && p == -1) break;
        cout << solve(n, p) << endl;;
    }

    return 0;
}
accuracy: 1
time_ms: 210
memory_kb: 3972
final_rank: 12

code_snippet: #include <iostream>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

const int MAX_PRIME = 200000;

vector<int> primes;
vector<bool> is_prime;

// 素数列挙（エラトステネスの篩）
void sieve() {
    is_prime.assign(MAX_PRIME + 1, true);
    is_prime[0] = is_prime[1] = false;
    for (int i = 2; i * i <= MAX_PRIME; ++i) {
        if (is_prime[i]) {
            for (int j = i * i; j <= MAX_PRIME; j += i)
                is_prime[j] = false;
        }
    }
    for (int i = 2; i <= MAX_PRIME; ++i) {
        if (is_prime[i])
            primes.push_back(i);
    }
}

int solve(int N, int P) {
    // N より大きい素数リストを作成
    vector<int> target_primes;
    for (int p : primes) {
        if (p > N)
            target_primes.push_back(p);
    }

    // 小さい和から順に P 個だけ取り出す：最小ヒープを使う
    using T = pair<int, pair<int, int>>; // {sum, {i, j}}
    priority_queue<T, vector<T>, greater<T>> pq;

    int size = target_primes.size();
    for (int i = 0; i < size; ++i) {
        pq.push({target_primes[i] + target_primes[i], {i, i}});
    }

    int count = 0;
    int answer = 0;
    while (count < P) {
        auto [sum, indices] = pq.top(); pq.pop();
        int i = indices.first;
        int j = indices.second;

        answer = sum;
        ++count;

        if (j + 1 < size) {
            pq.push({target_primes[i] + target_primes[j + 1], {i, j + 1}});
        }
    }

    return answer;
}

int main() {
    sieve();

    int N, P;
    while (cin >> N >> P) {
        if (N == -1 && P == -1) break;
        cout << solve(N, P) << endl;
    }

    return 0;
}
accuracy: 1
time_ms: 210
memory_kb: 3864
final_rank: 11

code_snippet: // B-Matsuzaki Number
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<ll(n);i++)
#define rep2(i,m,n) for(ll i=ll(m);i<ll(n);i++)
using vl = vector<ll>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using pl = pair<ll,ll>;
using vpl = vector<pl>;
using vvpl = vector<vpl>;
#define pb push_back

const long double EPS = 0.0000000001;
const ll INF = 1000000000000000000;
const double pi = std::acos(-1.0);

__int128 read_int128(){ //__int128を入力する
    string S;
    cin >> S;
    int N = S.size();
    int st = 0;
    bool minus = false;
    if(S[0] == '-'){
        minus = true;
        st = 1;
    }
    __int128 res = 0;
    rep2(i,st,N) res = res*10+int(S[i]-'0');
    if(minus) res *= -1;
    return res;
}

std::ostream &operator<<(std::ostream &dest, __int128_t value) { //これでcoutで__int128を出力できるように
    std::ostream::sentry s(dest);
    if(s){
        __uint128_t tmp = value < 0 ? -value : value;
        char buffer[128];
        char *d = std::end(buffer);
        do{
            d--;
            *d = "0123456789"[tmp%10];
            tmp /= 10;
        }while(tmp != 0);
        if(value < 0){
            d--;
            *d = '-';
        }
        int len = std::end(buffer)-d;
        if(dest.rdbuf()->sputn(d, len) != len) dest.setstate(std::ios_base::badbit);
    }
    return dest;
}

void Yes(){ cout << "Yes" << endl; } //文字列"Yes"を標準出力
void No(){ cout << "No" << endl; } //文字列"No"を標準出力

template<class T> bool chmin(T& a,T b){
    if(a > b){
        a = b;
        return true;
    }
    else return false;
}

template<class T> bool chmax(T& a,T b){
    if(a < b){
        a = b;
        return true;
    }
    else return false;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    vector<bool> Is_Prime(200000,true);
    Is_Prime[0] = Is_Prime[1] = false;
    for(int i=2;i<200000;i++){
        if(!Is_Prime[i]) continue;
        for(int j=2*i;j<200000;j+=i){
            Is_Prime[j] = false;
        }
    }
    vl Prime(0);
    rep(i,200000) if(Is_Prime[i]) Prime.push_back(i);
    vl pos(200000,-1);
    rep(i,Prime.size()) pos[Prime[i]] = i+1;
    for(int i=199998;i>=0;i--){
        if(!Is_Prime[i]){
            if(Is_Prime[i+1]) pos[i] = pos[i+1]-1;
            else pos[i] = pos[i+1];
        }
    }
    for(;;){
        ll N,P;
        cin >> N >> P;
        if(N == -1) break;
        vl sum_list(0);
        rep(i,P){
            rep2(j,i,i+P){
                ll pos1 = pos[N]+i;
                ll pos2 = pos[N]+j;
                sum_list.push_back(Prime[pos1]+Prime[pos2]);
            }
        }
        sort(sum_list.begin(),sum_list.end());
        cout << sum_list[P-1] << endl;
    }
}
accuracy: 1
time_ms: 110
memory_kb: 4984
final_rank: 15

code_snippet: #include <bits/stdc++.h>


using namespace std;
//make -f ../makefile SRC=
/*
background:
https://en.wikipedia.org/wiki/Goldbach%27s_conjecture
Goldbach's conjecture:
It states that every even natural number > 2 is the sum of 2 primes
*/


//------------------------------------------------------------------------------
bool DEBUG = false;
const int INF = 1000000000;

const int MAX_V = 200274;
static bool is_prime[MAX_V+1];
//static int SPF[MAX_V+1];

const int NP = 18007;
static vector<int> primes(NP);
//static vector<int> primes;
//------------------------------------------------------------------------------
void sieve()
{
    is_prime[0] = false;
    is_prime[1] = false;

    for (int i=2; i<=MAX_V; i++) is_prime[i] = true;

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

    /*
    SPF[1] = 1;
    for (int i=2; i<=MAX_V; i++) SPF[i] = i;

    for (int i=4; i<=MAX_V; i+=2) SPF[i] = 2;

    for (int i=3; i*i<=MAX_V; i++)
    {
        if (SPF[i] != i) continue;
        for (int j=i*i; j<=MAX_V; j+=i)
            if (SPF[j] == j)
                SPF[j] = i;
    }
    */
    int index = 0;
    for (int i=2; i<=MAX_V; i++)
        if (is_prime[i])
            primes[index++] = i;
            //primes.push_back(i);
    //if (DEBUG) printf("primes.size()=%ld\n", primes.size());
}


//------------------------------------------------------------------------------
int solve(int N, int K)
{
    auto it = lower_bound(primes.begin(), primes.end(), N);
    if (*it == N && it != primes.end()) it++;

    vector<int> S;https://en.wikipedia.org/wiki/Goldbach%27s_conjecture
    vector<int> P;

    for (it; S.size()<300 && it!=primes.end(); ++it)
    {
        int v2 = *it;

        S.push_back(v2+v2);
        for (int v1: P) S.push_back(v1+v2);

        P.push_back(v2);
    }
    if (DEBUG) {printf("P: "); for (int i=0; i<P.size(); ++i) printf("%d ",P[i]); printf("\n");}
    sort(S.begin(), S.end());
    if (DEBUG) {printf("S: "); for (int x: S) printf("%d ",x); printf("\n");}

    return S[K-1];
}

//------------------------------------------------------------------------------
void test()
{
    int res = solve(0, 55);
    printf("%d\n", res);
}

//------------------------------------------------------------------------------
int main()
{
    //DEBUG = true;
    sieve();
    //test(); return 0;
    //return 0;
    //--------------------------------------------------------------------------
    int N, K, num;
    while (true)
    {
        num = scanf("%d %d ", &N, &K);
        if (N == -1 && K == -1) break;
        int res = solve(N, K);
        printf("%d\n", res);
    }
    //--------------------------------------------------------------------------
    return 0;
}
//------------------------------------------------------------------------------
accuracy: 1
time_ms: 10
memory_kb: 3708
final_rank: 1

code_snippet: #include<bits/stdc++.h>
// #include<atcoder/all>
// #include<boost/multiprecision/cpp_int.hpp>

using namespace std;
// using namespace atcoder;
// using bint = boost::multiprecision::cpp_int;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using P = pair<ll,ll>;
using vi = vector<ll>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using ve = vector<vector<int>>;
using vb = vector<bool>;
using vvb = vector<vb>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define sz(c) ((ll)(c).size())
#define LB(A,x) (int)(lower_bound(A.begin(),A.end(),x)-A.begin())
#define UB(A,x) (int)(upper_bound(A.begin(),A.end(),x)-A.begin())
// #define MOD 1000000007
#define MOD 998244353
template<typename T>using min_priority_queue=priority_queue<T,vector<T>,greater<T>>;
template<typename T>ostream&operator<<(ostream&os,vector<T>&v){for(int i = 0;i < v.size();i++)os<<v[i]<<(i+1!=v.size()?" ":"");return os;}
template<typename T>istream&operator>>(istream&is,vector<T>&v){for(T&in:v)is>>in;return is;}
template<typename T1,typename T2>ostream&operator<<(ostream&os,pair<T1,T2>&p){os<<p.first<<" "<<p.second;return os;}
template<typename T1,typename T2>istream&operator>>(istream&is,pair<T1,T2>&p){is>>p.first>>p.second;return is;}
template<typename T> inline bool chmax(T &a,T b){if(a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a,T b){if(a > b){a = b;return true;}return false;}
ld dist(ld x1,ld y1,ld x2, ld y2){return sqrtl((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));}


vector<int> sieve(int n){
  vector<int> res;
  vector<bool> used(n+1,0);
  for(int i = 2;i <= n;i++){
    if(used[i])continue;
    res.push_back(i);
    for(int j = i;j <= n;j += i){
      used[j] = true;
    }
  }
  return res;
}

int main(){
  
  ios_base::sync_with_stdio(0), cin.tie(0);
  vector<int> p(sieve(200000));
  while(1){
    int n,P;cin >> n >> P;
    if(n == -1)break;
    vi v(100);
    int k = LB(p,n+1);
    rep(i,100)v[i] = p[k+i];
    vi enu;
    rep(i,100)rep(j,100)if(i <= j)enu.emplace_back(v[i]+v[j]);
    sort(ALL(enu));
    cout << enu[P-1] << "\n";
  }
  

  return 0;
}
accuracy: 1
time_ms: 170
memory_kb: 3616
final_rank: 8