Language: C++

import java.util.*;

class Main {

    static Scanner scan = new Scanner(System.in);

    public static void main(String[] args) {

        while (scan.hasNext()) {
            int n = scan.nextInt();
            int money = scan.nextInt();
            boolean[] dp = new boolean[money+1];
            if (n == 0) {
                break;
            }
            int[] menu = new int[30];
            for (int i = 0; i < n; i++) {
                menu[i] = scan.nextInt();
            }
            solve(dp, menu);
            int i;
            for (i = dp.length-1; i >= 0; i--) {
                if (dp[i] && prime(i)) {
                    break;
                }
            }
            if (i < 0) {
                System.out.println("NA");
            } else {
                System.out.println(i);
            }
        }
    }

    public static void solve(boolean dp[], int menu[]) {
        for (int i = 0; i < menu.length; i++) {
            if (menu[i] > dp.length) {
                continue;
            }
            dp[menu[i]] = true;
            for (int j = 1; j < dp.length; j++) {
                if (dp[j] && j + menu[i] < dp.length) {
                    dp[j+menu[i]] = true;
                }
            }
        }
    }



    public static boolean prime(int a) {
        if (a <= 3) {
            return true;
        } else {
            for (int i = 2; i * i <= a; i++) {
                if (a % i == 0) {
                    return false;
                }
            }
        }
        return true;
    }
}

Compiler output:
a.cc:1:1: error: 'import' does not name a type
    1 | import java.util.*;
      | ^~~~~~
a.cc:1:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:5:12: error: 'Scanner' does not name a type
    5 |     static Scanner scan = new Scanner(System.in);
      |            ^~~~~~~
a.cc:7:11: error: expected ':' before 'static'
    7 |     public static void main(String[] args) {
      |           ^~~~~~~
      |           :
a.cc:7:29: error: 'String' has not been declared
    7 |     public static void main(String[] args) {
      |                             ^~~~~~
a.cc:7:38: error: expected ',' or '...' before 'args'
    7 |     public static void main(String[] args) {
      |                                      ^~~~
a.cc:35:11: error: expected ':' before 'static'
   35 |     public static void solve(boolean dp[], int menu[]) {
      |           ^~~~~~~
      |           :
a.cc:35:30: error: 'boolean' has not been declared
   35 |     public static void solve(boolean dp[], int menu[]) {
      |                              ^~~~~~~
a.cc:51:11: error: expected ':' before 'static'
   51 |     public static boolean prime(int a) {
      |           ^~~~~~~
      |           :
a.cc:51:19: error: 'boolean' does not name a type; did you mean 'bool'?
   51 |     public static boolean prime(int a) {
      |                   ^~~~~~~
      |                   bool
a.cc:63:2: error: expected ';' after class definition
   63 | }
      |  ^
      |  ;
a.cc: In static member function 'static void Main::main(int*)':
a.cc:9:16: error: 'scan' was not declared in this scope
    9 |         while (scan.hasNext()) {
      |                ^~~~
a.cc:12:13: error: 'boolean' was not declared in this scope; did you mean 'bool'?
   12 |             boolean[] dp = new boolean[money+1];
      |             ^~~~~~~
      |             bool
a.cc:12:21: error: expected primary-expression before ']' token
   12 |             boolean[] dp = new boolean[money+1];
      |                     ^
a.cc:16:16: error: structured binding declaration cannot have type 'int'
   16 |             int[] menu = new int[30];
      |                ^~
a.cc:16:16: note: type must be cv-qualified 'auto' or reference to cv-qualified 'auto'
a.cc:16:16: error: empty structured binding declaration
a.cc:16:19: error: expected initializer before 'menu'
   16 |             int[] menu = new int[30];
      |                   ^~~~
a.cc:18:17: error: 'menu' was not declared in this scope
   18 |                 menu[i] = scan.nextInt();
      |                 ^~~~
a.cc:20:19: error: 'dp' was not declared in this scope
   20 |             solve(dp, menu);
      |                   ^~
a.cc:20:23: error: 'menu' was not declared in this scope
   20 |             solve(dp, menu);
      |                       ^~~~
a.cc:23:30: error: 'prime' was not declared in this scope
   23 |                 if (dp[i] && prime(i)) {
      |                              ^~~~~
a.cc:28:17: error: 'System' was not declared in this scope
   28 |                 System.out.println("NA");
      |                 ^~~~~~
a.cc:30:17: error: 'System' was not declared in this scope
   30 |                 System.out.println(i);
      |                 ^~~~~~
a.cc: In static member function 'static void Main::solve(int*, int*)':
a.cc:36:34: error: request for member 'length' in 'menu', which is of non-class type 'int*'
   36 |         for (int i = 0; i < menu.length; i++) {
      |                                  ^~~~~~
a.cc:37:30: error: request for member 'length' in 'dp', which is of non-class type 'int*'
   37 |             if (menu[i] > dp.length) {
      |                              ^~~~~~
a.cc:41:36: error: request for member 'length' in 'dp', which is of non-class type 'int*'
   41 |             for (int j = 1; j < dp.length; j++) {
      |                                    ^~~~~~
a.cc:42:47: error: request for member 'length' in 'dp', which is of non-class type 'int*'
   42 |                 if (dp[j] && j + menu[i] < dp.length) {
      |                                               ^~~~~~