Go: package main

import (
	"bufio"
	"os"
	"strings"
	"strconv"
	"fmt"
	)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	for scanner.Scan() {
		buf := strings.Split(scanner.Text(), " ")
		n, _ := strconv.Atoi(buf[0])
		x, _ := strconv.Atoi(buf[1])
		prime_table := make([]int, 1000001)
		prime_table[0] = -1
		prime_table[1] = -1
		for i := 2; i < 1000001; i++ {
			if ^prime_table[i] != 0 {
				prime_table[i] = 1
				for j := 2*i; j < 1000001; j += i {
					prime_table[j] = -1 // -1 means "not prime"
				}
			}
		}
		dp := make([]int, x+1)
		dp[0] = 1
		menu := make([]int, n)
		for i := 0; i < n; i++ {
			scanner.Scan()
			menu[i], _ = strconv.Atoi(scanner.Text())
		}
		for i := 0; i < n; i++ {
			for j := 0; j <= x; j++ {
				if menu[i] <= j && dp[j-menu[i]] != 0 {
					// log.Println(dp)
					dp[j] = 1
				}
			}
		}
		flag := true
		for j := x; j >= 0; j-- {
			if prime_table[j] == 1 && dp[j] == 1 {
				flag = false
				fmt.Println(j)
				break
			}
		}
		if flag {
			fmt.Println("NA")
		}
	}
}

C++: #include<iostream>

using namespace std;

bool isprime[1000001];//false????´???°

int main() {
	isprime[1] = true;
	int n, x;
	int price[30];

	for (int i = 2; i <= 1000000; i++) {
		if (!isprime[i]) {
			for (int j = i * 2; j <= 1000000; j += i) {
				isprime[j] = true;
			}
		}
	}

	while (cin >> n >> x, n * x) {
		bool isprice[1000001];//??????????????????????????????true
		for (int i = 0; i < n; i++) {
			cin >> price[i];
			isprice[price[i]] = true;
		}
		for (int i = 1; i <= x; i++) {
			if (isprice[i]) {
				for (int j = 0; j < n; j++) {
					if (i + price[j] <= x) {
						isprice[i + price[j]] = true;
					}
				}
			}
		}
		int ans = 99999999;
		for (int i = x;i >= 1; i--) {
			if (!isprime[i] && isprice[i]) {
				ans = i;
				break;
			}
		}
		if (ans == 99999999)cout << "NA" << endl;
		else cout << ans << endl;
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define ANSWER(x) cout<<x<<endl
#define debug(x) cout<<#x<<": "<<x
const int MAX_INT = 1000000;
bool er[1000001];
int n,x,ans;
int v[31];
int solve(int k,int m);
int memo[1000001];
int main(){
  memset(er,true,sizeof(er));
  for(int i=2;i<=sqrt(MAX_INT);i++){
    if(er[i]){
      for(int j=0;i*(j+2)<MAX_INT;j++){
	er[i*(j+2)]=false;
      }
    }
  }
  while(cin >> n >> x){
    if(!n && !x)break;
    memset(memo,-1,sizeof(memo));
    for(int i=0;i<n;i++){
      cin >> v[i];
    }
    
    ans = solve(0,0);
    if(!ans)cout << "NA\n";
    else cout << ans << endl;
  }
}
int solve(int k,int m){
  if(memo[m] != -1)return memo[m];
  if(m > x)return 0;
  else if(k == n){
    if(m == 0)return 0;
    if(er[m])return m;
    else return 0;
  }
  return memo[m] = max(solve(k,m+v[k]),solve(k+1,m));
}

C++: #include<iostream>
#include <cstdio>
#include<string>
#include<math.h>
using namespace std;
//int ha(string);
//int saga(int);
int q,m,n=1000000,List[1000];
bool  slist[1000001];
bool  klist[1000001];

int main()
{	
	int i,j,k,b=0,s,a=2,f=0,c=0;
	for( i = 0; i <n;i++ ){
		slist[i]=true;
		klist[i]=false;
	}

	i=0;
	while(i<sqrt((double)n)){
		for(i=a+a;i<n;i=i+a){
			slist[i]=false;
		}
		for(i=a+1;i<sqrt((double)n);i++){
			if(slist[i]==true){
				a=i;
				break;
			}
		}
	}
	cin>>m>>n;
	while(m!=0||n!=0){
	for( i = 0; i <=n;i++ ){
		klist[i]=false;
	}
	for(i=0;i<m;i++){
		cin>>List[i];
		klist[List[i]]=true;
	}
		for(i=0;i<=n;i++){
			if(klist[i]){
			for(j=0;j<m;j++){				
				klist[i+List[j]]=true;
			}
		}
	}
		for(i=n;i>0;i--){
			if(klist[i]&&slist[i]){
			break;
		}
	}
		if(i==0){
			printf("NA\n");
		}
		else{
		printf("%d\n",i);
		}
		cin>>m>>n;
	}
	return 0;
}

C++: #include <stdio.h>


int *ms;
int n, m;

int *dp;

int search(int m){
	if(m == 0) return 1;
	else if(m < 0) return 0;
	else if(dp[m]!=-1) return dp[m];

	for(int i=0;i<n;i++){
		if(search(m-ms[i])) return dp[m] = 1;
	}
	
	return dp[m]=0;
}

int isprime(int p){
	if(p%2==0) return 0;
	for(int i=3;i*i<p;i++){
		if(p%i==0) return 0;
	}
	return 1;
}

int main(){
	while(1){
		scanf("%d%d", &n,&m);
		
		if(n==0) break;
		
		int i;
		dp = new int[m+1];
		for(i=0;i<m+1;i++) dp[i]=-1;
		
		ms = new int[n];
		for(i=0;i<n;i++) scanf("%d", ms+i);
		
		int flag = 1;
		for(i=m;i>=0;i--){
			if(search(i) && isprime(i)){
				printf("%d\n", i);
				flag = 0;
				break;
			}
		}
		if(flag) puts("NA");
	}
}

C++: #include <iostream>
#include <vector>
using namespace std;

bool prime[1000001];
vector<int> p;

int main(){
	for(int i = 2;i <= 1000000;i++) prime[i] = true;
	for(int i = 4;i <= 1000000;i += 2) prime[i] = false;
	for(int i = 3;i <= 1000;i += 2){
		for(int j = 2 * i;j <= 1000000;j += i) prime[j] = false;
	}
	for(int i = 0;i <= 1000000;i++) if(prime[i]) p.push_back(i);
	
	int n,x;
	while(1){
		cin >> n >> x;
		if(!n) break;
		bool dp[1000001] = {true};
		for(int i = 0;i < n;i++){
			int v;
			cin >> v;
			for(int j = v;j <= x;j++){
				if(dp[j - v]) dp[j] = true;
			}
		}
		int i;
		for(i = x;i >= 0;i--){
			if(prime[i] && dp[i]) {
				cout << i << endl;
				break;
			}
		}
		if(i == -1) cout << "NA" << endl;
	}
	return 0;
}

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

int main() {
    int N, K;

    bool is_prime[1000001];
    for (int i = 0; i <= 1000000; i++) is_prime[i] = true;
    is_prime[0] = is_prime[1] = 0;
    for (int i = 0; i <= 1000000/2; i++) {
        if (is_prime[i])
            for (int j = 2; j * i <= 1000000; j++) {
                is_prime[i * j] = false;
            }
    }

    while (cin >> N >> K, N || K) {
        vector<int> v(N);
        for (auto& i : v) cin >> i;

        vector<bool> dp(K+1, false);
        dp[0] = true;
        int ans = -1;
        for (int i = 0; i < K; i++) {
            if (dp[i]) {
                for (auto j : v) {
                    if (i + j <= K) dp[i + j] = true;
                    if (i + j <= K && is_prime[i+j])
                        ans = max(ans, i + j);
                }
            }
        }

        if (ans >= 0) cout << ans << endl;
        else cout << "NA" << endl;
    }

    return 0;
}

C++: #include<iostream>
#include<cstring>
using namespace std;

bool prime[10000001];
bool dp[10000001];
int menu[30];
int n,x;

void make_prime()
{
  memset(prime,true,sizeof(prime));
  prime[0]=prime[1]=false;
  for(int i=2;i<10000001;i++)
    {
      if(prime[i])
	{
	  for(int j=i+i;j<10000001;j+=i)
	    prime[j]=false;
	}
    }
}

int main()
{
  make_prime();
  for(;cin>>n>>x,n;)
    {
      memset(dp,false,sizeof(dp));
      for(int i=0;i<n;i++)
	{
	  cin>>menu[i];
	  dp[menu[i]]=true;	  
	}
      int ans=-1;
      for(int i=0;i<10000001;i++)
	{
	  if(dp[i])
	    for(int j=0;j<n;j++)
	      if(i+menu[j]<10000001)
		dp[i+menu[j]]=true;	  
	}
      for(int i=x;i>0;i--)
	if(prime[i]&&dp[i])
	  {
	    ans=i;
	    break;
	  }
      if(ans!=-1)
	cout<<ans<<endl;
      else
	cout<<"NA"<<endl;
    }
}

C++: #include<stdio.h>
#include<string.h>
#include<iostream>
int hideo[2000001] = { 0 };
int noyori = 0, debu = 0, n, temp = 1, ruio[31] = { 0 };
unsigned int x;
int main(void)
{
	while (scanf("%d %d", &n, &x)) {
		if (n == 0 && x == 0) {
			return 0;
		}
		for (int i = 1; i <= n; i++) {
			scanf("%d", &ruio[i]);
			hideo[ruio[i]] = 1;
		}
		while (temp != x) {
			if (hideo[temp] == 1) {
				for (int j = 1; j <= n; j++) {
					if (temp + ruio[j] > x)continue;
					if (hideo[temp + ruio[j]] == 0) {
						hideo[temp + ruio[j]] = 1;
					}
				}
			}
			temp++;
		}
		for (int i = x; i >= 1; i--) {
			if (hideo[i] == 1) {
				for (int j = 2; j < i - 1; j++) {
					if (i%j == 0) {
						debu = 1;
					}
				}
				if (debu == 0) {
					noyori = i;
					break;
				}
			}
			debu = 0;
		}
		if (noyori > 1) {
			printf("%d\n", noyori);
		}
		else {
			printf("NA\n");
		}
		temp = 1;
		noyori = 0;
		debu = 0;
		for (int i = 0; i <= n; i++) {
			ruio[i] = 0;
		}
		for (int i = 1; i <= x; i++) {
			hideo[i] = 0;
		}
	}
	return 0;
}