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])
		if n == 0 && x == 0 {
			break
		}
		prime_table := make([]int, 1000001)
		prime_table[0] = -1
		prime_table[1] = -1
		for i := 2; i < 1000001; i++ {
			if prime_table[i] != -1 {
				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;

#define N 30
#define P 1000003

#define max(a,b) (a>b?a:b)

int main() {
	int n, x, c, dp[P], p[P], ans;
	for(int i=0; i<P; ++i) p[i] = 1;
	p[0] = p[1] = 0;
	for(int i=2; i<P; ++i) {
		if(p[i]&&i<P/i) for(int j=i*i; j<P; j+=i) p[j]=0;
	}
	while(1) {
		cin >> n >> x;
		if(!n&&!x) break;
		ans = 0;
		for(int i=0; i<=x; ++i) dp[i] = 0;
		dp[0] = 1;
		for(int i=0; i<n; ++i) {
			cin >> c;
			for(int j=0; j<=x-c; ++j) {
				if(dp[j]) {
					dp[j+c] = 1;
					if(p[j+c]) ans = max(ans, j+c);
				}
			}
		}
		if(ans==0) cout << "NA" << endl;
		else cout << ans << endl;
	}
	return 0;
}

C++: #include<cstdio>
#include<iostream>
#include<algorithm>

using namespace std;

#define reps(i,f,n) for(int i=f;i<int(n);i++)
#define rep(i,n) reps(i,0,n)

int memo[1000001];
int sosu[1000001];

int main(){
  rep(i,1000001)sosu[i]=0;
  sosu[0]=sosu[1]=1;
  rep(i,1000001){
    if(sosu[i]==1)continue;
    for(int j=i*2;j<1000001;j+=i){
      sosu[j]=1;
    }
  }

 A:;
  int n,m;
  cin>>n>>m;
  if(n==0)return 0;

  int sina[101];
  rep(i,n){
    cin>>sina[i];
  }
  sort(sina, sina+n);

  rep(i,1000001)memo[i]=0; 

  memo[0]=1;

  rep(i,m+1){
    if(memo[i]==1){
      rep(j,n){
	if(i+sina[j]>m)break;
	memo[i+sina[j]]=1;
      }
    }
  }

  int maxi=-1;
  rep(i,m+1){
    if(sosu[i]==0 && memo[i]==1)maxi=max(maxi,i);
  }

  if(maxi==-1)puts("NA");
  else printf("%d\n",maxi);

  goto A;
}

C++: #define _USE_MATH_DEFINES
#include<cstdio>
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<stack>
#include<cmath>
#include<climits>
#include<map>
#include<string>
using namespace std;

bool is_prime[ (int)1e6+1 ];

int main(){
	fill_n(is_prime, 1e6+1, true);
	is_prime[0] = is_prime[1] = false;
	for(int i = 2; i <= 1e6; i++){
		if(!is_prime[i]) continue;
		for(int j = 2; i*j <= 1e6; j++) is_prime[i*j] = false;
	}

	int N, X;
	while(cin >> N >> X, N || X){
		int C[30], ans = -1;
		bool dp[ (int)1e6+1 ] = {};
		for(int i = 0; i < N; i++){
			cin >> C[i];
		}
		dp[0] = true;
		for(int j = 0; j < X; j++){
			if(!dp[j]) continue;
			for(int k = 0; k < N; k++){
				if(j + C[k] > X) continue;
				dp[j + C[k]] = true;
				if(is_prime[j + C[k]]) ans = max(ans, j + C[k]);
			}
		}
		if(ans == -1) puts("NA");
		else printf("%d\n", ans);
	}
	return 0;
}

C++: #include <stdio.h>
#include <algorithm>
using namespace std;
int n, x, a[30]; bool dp[1000001], prime[1000001];
int main() {
	prime[0] = true, prime[2] = true;
	for(int i = 3; i <= 1000000; i += 2) prime[i] = true;
	for(int i = 3; i <= 1000; i += 2) {
		if(!prime[i]) continue;
		for(int j = i * i; j <= 1000000; j += i * 2) prime[j] = false;
	}
	while(scanf("%d%d", &n, &x), n) {
		for(int i = 0; i < n; i++) scanf("%d", &a[i]); sort(a, a + n);
		for(int i = 0; i < x; i++) dp[i + 1] = false; dp[0] = true;
		for(int i = 1; i <= x; i++) {
			for(int j = 0; j < n && i >= a[j]; j++) {
				if(dp[i - a[j]]) {
					dp[i] = true; break;
				}
			}
		}
		for(int i = x; i >= 0; i--) {
			if(dp[i] && prime[i]) {
				printf(i ? "%d\n" : "NA\n", i); break;
			}
		}
	}
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
bool dp[1000001]={true},prime[1000001]={true,true};
int solve(int &i){
  while(i--) if(dp[i] && !prime[i]) return i;
}
int main(){
  int n,x,data[30],ans;
  for(int i = 2 ; i * i <= 1000001 ; i++ ){
    if(!prime[i]) for(int j = 2 ; i * j < 1000001 ; j++ ) prime[i*j] = true;
  }
  while(cin >> n >> x , n){
    for(int i = 1 ; i <= x ; i++ ) dp[i] = false;
    for(int i = 0 ; i < n ; i++ ) cin >> data[i];
    for(int i = 0 ; i <= x ; i++ ){
      if(dp[i]) for(int j = 0 ; j < n ; j++ )
        if(i+data[j] <= x) dp[i+data[j]] = true;
    }
    if(ans = solve(x)) cout << ans << endl;
    else cout << "NA" << endl;
  }
}

C++: #include <iostream>
#include <cmath>
using namespace std;
#define KMAX  30
#define VMAX  1000000

int main(){
  int k, v;
  int K[KMAX];
  char T[VMAX+1];
  bool prime[VMAX+1];
  for (int i=0;i<=VMAX;i++) prime[i] = false;
  for (int i=3;i<=VMAX;i+=2) prime[i] = true;
  prime[2] = true;
  int limit = (int)sqrt((double)VMAX) + 1;
  for (int i=3;i<=limit;i+=2){
    if (!prime[i]) continue;
    for (int j=i+i;j<=VMAX;j+=i) prime[j] = false;
  }

  while (cin >> k >> v && !(k ==0 && v ==0)){
    for (int i=0;i<k;i++) cin >> K[i];
    for (int j=0;j<=v;j++) T[j]=0;
    T[0]=1;
    for (int j=K[0];j<=v;j+=K[0]) T[j]=1;
    for (int i=1;i<k;i++){
      for (int j=K[i];j<=v;j++){
        T[j] = (T[j] | T[j-K[i]]);
      }
    }
    int ans = -1;
    for (int i=v;i>1;i--)
      if (prime[i] && T[i]){
        ans = i;
        break;
      }
    if (ans==-1)
      cout << "NA" << endl;
    else
      cout << ans << endl;
  }
  return 0;
}

C++: #include<map>
#include<list>
#include<queue>
#include<stack>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
int a[1000000];
int m[1000000];
int s[1000000];

int isPrime(int x){
	if (x < 2)return 0;
	else if (x == 2) return 1;
	if (x % 2 == 0) return 0;
	for (int i = 3; i*i <= x; i += 2){
		if (x%i == 0) return 0;
	}
	return 1;
}


int main(){
	int n; int x; int temp = 0;
	for (int i = 0; i <= 1000000; i++){
		s[i] = isPrime(i);
	}
	while (cin >> n >> x, n, x){
		memset(a, 0, sizeof(a));
		memset(m, 0, sizeof(m));
		for (int i = 0; i < n; i++){
			cin >> a[i];
			m[a[i]] = 1;
		}
		for (int i = 0; i <= x; i++){
			if (m[i] == 1){
				for (int j = 0; j < n; j++){
					if (x >= a[j] + i){
						m[a[j] + i] = 1;
					}
				}
			}
		}
		bool flag = false;
		for (int i = x; i >0; i--){
			if (m[i] == 1 && s[i] == 1){
				cout << i << endl;
				flag = true;
				break;
			}
		}
		if (!flag) cout << "NA" << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <climits>

using namespace std;

int main() {
	bool p[1000001];
	int n, x;

	p[0] = false;
	p[1] = false;
	for(int i = 2; i <= 1000000; i++) {
		p[i] = true;
	}

	for(int i = 2; i * i <= 1000000; i++) {
		for(int j = 2; j * i <= 1000000; j++) {
			p[i * j] = false;
		}
	}

	while( true ) {
		cin >> n >> x;

		if(n == 0 && x == 0) {
			break;
		}

		vector< int > dp(x + 1, 0);
		vector< int > money(n);

		for(int i = 0; i < n; i++) {
			cin >> money[i];
		}

		for(int i = 0; i < n; i++) {
			dp[money[i]]++;
		}

		for(int i = 0; i <= x; i++) {
			for(int j = 0; j < n; j++) {
				if(dp[i] == 0 || i + money[j] > x) {
					continue;
				}
				dp[i + money[j]]++;
			}
		}

		int ans = 0;
		for(int i = x; i >= 0; i--) {
			if(p[i] == true && dp[i] > 0) {
				ans = i;
				break;
			}
		}

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