Language: C++


import java.util.*;
import java.io.*;
import java.math.BigDecimal;
import java.awt.geom.*;
import static java.util.Arrays.*;
import static java.lang.Math.*;

public class Main{

    static final Reader sc = new Reader();
    static final PrintWriter out = new PrintWriter(System.out,false);

    public static void main(String[] args) throws Exception {
        int k = 250000;
        boolean[] judge = new boolean[k];
        Arrays.fill(judge,true);
        judge[0] = false;
        judge[1] = false;
        for(int i=4;i<k;i+=2){
        	judge[i] = false;
        }
        for(int i=3;i<k;i+=2){
        	if(judge[i]){
        		for(int j=i*2;j<k;j+=i){
        			judge[j] = false;
        		}
        	}
        }
        while(true){
        	int n = sc.nextInt();
        	int p = sc.nextInt();
        	if(n==-1 && p==-1){
        		break;
        	}
        	int[] num = new int[p*p+p];
        	Arrays.fill(num,Integer.MAX_VALUE/2);
        	int count1 = n+1;
        	int count2 = n+1;
        	int counter = 0;
        	for(int i=0;i<p;i++){
        		if(judge[count1]){
        			count2 = count1;
        			for(int j=0;j<p;j++){
        				if(judge[count2]){
        					num[counter] = count1+count2;
        					counter++;
        				}
        				else{
        					j--;
        				}
        				count2++;
        			}
        		}
        		else{
        			i--;
        		}
        		count1++;
        	}
        	Arrays.sort(num);
        	out.println(num[p-1]);
        	out.flush();
        }
        sc.close();
        out.close();
    }

    static void trace(Object... o) { System.out.println(Arrays.deepToString(o));}
}

class Reader {
    private final InputStream sc;
    private final byte[] buf = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    public Reader() { this(System.in);}
    public Reader(InputStream source) { this.sc = source;}

    private boolean hasNextByte() {
        if (ptr < buflen) return true;
        ptr = 0;
        try{
            buflen = sc

.read(buf);
        }catch (IOException e) {e.printStackTrace();}
        if (buflen <= 0) return false;
        return true;
    }

    private int readByte() { if (hasNextByte()) return buf[ptr++]; else return -1;}

    private boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}

    private void skip() { while(hasNextByte() && !isPrintableChar(buf[ptr])) ptr++;}

    public boolean hasNext() {skip(); return hasNextByte();}

    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        boolean minus = false;
        long num = readByte();

        if(num == '-'){
            num = 0;
            minus = true;
        }else if (num < '0' || '9' < num){
            throw new NumberFormatException();
        }else{
            num -= '0';
        }
        
        while(true){
            int b = readByte();
            if('0' <= b && b <= '9')
                num = num * 10 + (b - '0');
            else if(b == -1 || !isPrintableChar(b))
                return minus ? -num : num;
            else
                throw new NoSuchElementException();
        }
    }

    public int nextInt() {
        long num = nextLong();
        if (num < Integer.MIN_VALUE || Integer.MAX_VALUE < num)
            throw new NumberFormatException();
        return (int)num;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }

    public char nextChar() {
        if (!hasNext()) throw new NoSuchElementException();
        return (char)readByte();
    }

    public String nextLine() {
        while (hasNextByte() && (buf[ptr] == '\n' || buf[ptr] == '\r')) ptr++;
        if (!hasNextByte()) throw new NoSuchElementException();

        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (b != '\n' && b != '\r') {
            sb.appendCodePoint(b);
            b = readByte();
        }

        return sb.toString();
    }

    public int[] nextIntArray(int n) {
        int[] res = new int[n];
        for (int i=0; i<n; i++) res[i] = nextInt();
        return res;
    }

    public char[] nextCharArray(int n) {
        char[] res = new char[n];
        for (int i=0; i<n; i++) res[i] = nextChar();
        return res;
    }

    public void close() {try{ sc.close();}catch(IOException e){ e.printStackTrace();}};
}

Compiler output:
a.cc:2:1: error: 'import' does not name a type
    2 | import java.util.*;
      | ^~~~~~
a.cc:2:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:3:1: error: 'import' does not name a type
    3 | import java.io.*;
      | ^~~~~~
a.cc:3:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:4:1: error: 'import' does not name a type
    4 | import java.math.BigDecimal;
      | ^~~~~~
a.cc:4:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:5:1: error: 'import' does not name a type
    5 | import java.awt.geom.*;
      | ^~~~~~
a.cc:5:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:6:1: error: 'import' does not name a type
    6 | import static java.util.Arrays.*;
      | ^~~~~~
a.cc:6:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:7:1: error: 'import' does not name a type
    7 | import static java.lang.Math.*;
      | ^~~~~~
a.cc:7:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:9:1: error: expected unqualified-id before 'public'
    9 | public class Main{
      | ^~~~~~
a.cc:72:12: error: expected ':' before 'final'
   72 |     private final InputStream sc;
      |            ^~~~~~
      |            :
a.cc:72:13: error: 'final' does not name a type
   72 |     private final InputStream sc;
      |             ^~~~~
a.cc:73:12: error: expected ':' before 'final'
   73 |     private final byte[] buf = new byte[1024];
      |            ^~~~~~
      |            :
a.cc:73:13: error: 'final' does not name a type
   73 |     private final byte[] buf = new byte[1024];
      |             ^~~~~
a.cc:74:12: error: expected ':' before 'int'
   74 |     private int ptr = 0;
      |            ^~~~
      |            :
a.cc:75:12: error: expected ':' before 'int'
   75 |     private int buflen = 0;
      |            ^~~~
      |            :
a.cc:77:11: error: expected ':' before 'Reader'
   77 |     public Reader() { this(System.in);}
      |           ^~~~~~~
      |           :
a.cc:78:11: error: expected ':' before 'Reader'
   78 |     public Reader(InputStream source) { this.sc = source;}
      |           ^~~~~~~
      |           :
a.cc:78:30: error: expected ')' before 'source'
   78 |     public Reader(InputStream source) { this.sc = source;}
      |                  ~           ^~~~~~~
      |                              )
a.cc:80:12: error: expected ':' before 'boolean'
   80 |     private boolean hasNextByte() {
      |            ^~~~~~~~
      |            :
a.cc:80:13: error: 'boolean' does not name a type; did you mean 'bool'?
   80 |     private boolean hasNextByte() {
      |             ^~~~~~~
      |             bool
a.cc:92:12: error: expected ':' before 'int'
   92 |     private int readByte() { if (hasNextByte()) return buf[ptr++]; else return -1;}
      |            ^~~~
      |            :
a.cc:94:12: error: expected ':' before 'boolean'
   94 |     private boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
      |            ^~~~~~~~
      |            :
a.cc:94:13: error: 'boolean' does not name a type; did you mean 'bool'?
   94 |     private boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
      |             ^~~~~~~
      |             bool
a.cc:96:12: error: expected ':' before 'void'
   96 |     private void skip() { while(hasNextByte() && !isPrintableChar(buf[ptr])) ptr++;}
      |            ^~~~~
      |            :
a.cc:98:11: error: expected ':' before 'boolean'
   98 |     public boolean hasNext() {skip(); return hasNextByte();}
      |           ^~~~~~~~
      |           :
a.cc:98:12: error: 'boolean' does not name a type; did you mean 'bool'?
   98 |     public boolean hasNext() {skip(); return hasNextByte();}
      |            ^~~~~~~
      |            bool
a.cc:100:11: error: expected ':' before 'String'
  100 |     public String next() {
      |           ^~~~~~~
      |           :
a.cc:100:12: error: 'String' does not name a type
  100 |     public String next() {
      |            ^~~~~~
a.cc:111:11: error: expected ':' before 'long'
  111 |     public long nextLong() {
      |           ^~~~~
      |           :
a.cc:136:11: error: expected ':' before 'int'
  136 |     public int nextInt() {
      |           ^~~~
      |           :
a.cc:143:11: error: expected ':' before 'double'
  143 |     public double nextDouble() {
      |           ^~~~~~~
      |           :
a.cc:147:11: error: expected ':' before 'char'
  147 |     public char nextChar() {
      |           ^~~~~
      |           :
a.cc:152:11: error: expected ':' before 'String'
  152 |     public String nextLine() {
      |           ^~~~~~~
      |           :
a.cc:152:12: error: 'String' does not name a type
  152 |     public String nextLine() {
      |            ^~~~~~
a.cc:166:11: error: expected ':' before 'int'
  166 |     public int[] nextIntArray(int n) {
      |           ^~~~
      |           :
a.cc:166:15: error: expected unqualified-id before '[' token
  166 |     public int[] nextIntArray(int n) {
      |               ^
a.cc:172:11: error: expected ':' before 'char'
  172 |     public char[] nextCharArray(int n) {
      |           ^~~~~
      |           :
a.cc:172:16: error: expected unqualified-id before '[' token
  172 |     public char[] nextCharArray(int n) {
      |                ^
a.cc:178:11: error: expected ':' before 'void'
  178 |     public void close() {try{ sc.close();}catch(IOException e){ e.printStackTrace();}};
      |           ^~~~~
      |           :
a.cc:179:2: error: expected ';' after class definition
  179 | }
      |  ^
      |  ;
a.cc: In constructor 'Reader::Reader()':
a.cc:77:28: error: 'System' was not declared in this scope
   77 |     public Reader() { this(System.in);}
      |                            ^~~~~~
a.cc:77:37: error: expression cannot be used as a function
   77 |     public Reader() { this(System.in);}
      |                                     ^
a.cc: In member function 'int Reader::readByte()':
a.cc:92:34: error: 'hasNextByte' was not declared in this scope
   92 |     private int readByte() { if (hasNextByte()) return buf[ptr++]; else return -1;}
      |                                  ^~~~~~~~~~~
a.cc:92:56: error: 'buf' was not declared in this scope
   92 |     private int readByte() { if (hasNextByte()) return buf[ptr++]; else return -1;}
      |                                                        ^~~
a.cc: In member function 'void Reader::skip()':
a.cc:96:33: error: 'hasNextByte' was not declared in this scope
   96 |     private void skip() { while(hasNextByte() && !isPrintableChar(buf[ptr])) ptr++;}
      |                                 ^~~~~~~~~~~
a.cc:96:67: error: 'buf' was not declared in this scope
   96 |     private void skip() { while(hasNextByte() && !isPrintableChar(buf[ptr])) ptr++;}
      |                                                                   ^~~
a.cc:96:51: error: 'isPrintableChar' was not declared in this scope
   96 |     private void skip() { while(hasNextByte() && !isPrintableChar(buf[ptr])) ptr++;}
      |                                                   ^~~~~~~~~~~~~~~
a.cc: In member function 'long int Reader::nextLong()':
a.cc:112:14: error: 'hasNext' was not declared in this scope
  112 |         if (!hasNext()) throw new NoSuchElementException();
      |              ^~~~~~~
a.cc:112:35: error: expected type-specifier before 'NoSuchElementException'
  112 |         if (!hasNext()) throw new NoSuchElementException();
      |                                   ^~~~~~~~~~~~~~~~~~~~~~
a.cc:113:9: error: 'boolean' was not declared in this scope; did you mean 'bool'?
  113 |         boolean minus = false;
      |         ^~~~~~~
      |         bool
a.cc:118:13: error: 'minus' was not declared in this scope
  118 |             minus = true;
      |             ^~~~~
a.cc:120:23: error: expected type-specifier before 'NumberFormatException'
  120 |             throw new NumberFormatException();
      |                       ^~~~~~~~~~~~~~~~~~~~~
a.cc:129:33: error: 'isPrintableChar' was not declared in this scope
  129 |             else if(b == -1 || !isPrintableChar(b))
      |                                 ^~~~~~~~~~~~~~~
a.cc:130:24: error: 'minus' was not declared in this scope
  130 |                 return minus ? -num : num;
      |                        ^~~~~
a.cc:132:27: error: expected type-specifier before 'NoSuchElementException'
  132 |                 throw new NoSuchElementException();
      |                           ^~~~~~~~~~~~~~~~~~~~~~
a.cc: In member function 'int Reader::nextInt()':
a.cc:138:19: error: 'Integer' was not declared in this scope
  138 |         if (num < Integer.MIN_VALUE || Integer.MAX_VALUE < num)
      |                   ^~~~~~~
a.cc:139:23: error: expected type-specifier before 'NumberFormatException'
  139 |             throw new NumberFormatException();
      |                       ^~~~~~~~~~~~~~~~~~~~~
a.cc: In member function 'double Reader::nextDouble()':
a.cc:144:16: error: 'Double' was not declared in this scope; did you mean 'double'?
  144 |         return Double.parseDouble(next());
      |                ^~~~~~
      |                double
a.cc:144:35: error: 'next' was not declared in this scope; did you mean 'nextInt'?
  144 |         return Double.parseDouble(next());
      |                                   ^~~~
      |                                   nextInt
a.cc: In member function 'char Reader::nextChar()':
a.cc:148:14: error: 'hasNext' was not declared in this scope
  148 |         if (!hasNext()) throw new NoSuchElementException();
      |              ^~~~~~~
a.cc:148:35: error: expected type-specifier before 'NoSuchElementException'
  148 |         if (!hasNext()) throw new NoSuchElementException();
      |                                   ^~~~~~~~~~~~~~~~~~~~~~
a.cc: In member function 'void Reader::close()':
a.cc:178:31: error: 'sc' was not declared in this scope
  178 |     public void close() {try{ sc.close();}catch(IOException e){ e.printStackTrace();}};
      |                               ^~
a.cc:178:49: error: 'IOException' does not name a type
  178 |     public void close() {try{ sc.close();}catch(IOException e){ e.printStackTrace();}}