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] != -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<cstdio>
#include<cstdlib>
#include<ctime>
#include<cmath>
#include<cstring>
#include<cctype>
#include<complex>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<functional>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<bitset>
using namespace std;
const int dx[] = {1,0,-1,0};
const int dy[] = {0,1,0,-1};
#define INF 1e+8
#define EPS 1e-10
#define PB push_back
#define fi first
#define se second
#define ll long long 
#define reps(i,j,k) for(int i = (j); i < (k); i++)
#define rep(i,j) reps(i,0,j)
typedef pair<int,int> Pii;
typedef vector<int> vi;
bool PRIME[1000001];
void Prime(){ 
    PRIME[0]=PRIME[1]=true; 
    for(int i=2;i*i <= 1000000 ;i++){ 
        if(PRIME[i]==false){ 
            for(int j=i*i ; j<=1000000 ; j+=i){ 
                PRIME[j] = true; 
            } 
        } 
    } 
    return; 
}
int main(){
	Prime();
    int n,x;
    while(scanf("%d%d",&n,&x),n){
        int goods[32]={0};
		int dp[1000001]={0};
		int ans = -1;
        rep(i,n){
            scanf("%d",&goods[i]);
        }
        sort(goods,goods+n);
		rep(i,n){
			reps(j,goods[i],x+1){
				if(dp[j] < dp[j-goods[i]]+goods[i]){
					dp[j] = dp[j-goods[i]]+goods[i];
					if(!PRIME[dp[j]])ans = max(ans,dp[j]);
				}
			}
		}
		ans == -1 ? puts("NA") : printf("%d\n",ans);
	}
    return 0;
}

C++: #define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
const int X = 1001000;
signed main() {
	vector<bool>prime(X, true);
	prime[0] = prime[1] = false;
	for (int i = 2; i <= sqrt(X); i++) {
		if (prime[i]) {
			for (int j = i * 2; j < X; j += i) {
				prime[j] = false;
			}
		}
	}
	int n, x;
	while (cin >> n >> x,n||x) {
		vector<bool>money(x+100, false); money[0] = true;
		vector<int>v(n); rep(i, 0, n)cin >> v[i];
		rep(i, 0, n) {
			rep(j, 0, x+100 - v[i]) {
				if (money[j]) {
					money[j + v[i]] = true;
				}
			}
		}
		int ans(-1);
		for (int i = x ; i >= 1; i--) {
			if (prime[i] && money[i]) {
				ans = i;
				break;
			}
		}
		if (ans == -1)cout << "NA" << endl;
		else cout << ans << endl;

	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdlib>
using namespace std;

#define rep(i,a) for(int i = 0 ; i < a ; i ++)
#define loop(i,a,b) for(int i = a ; i < b ; i ++)

int dt[40];
bool prime[100000];
bool dp[1000000];

int main(void){
	int n, x,lm;
	rep(i,100000){
		prime[i]=true;
	}
	for(int i=2;i<1000000;i++){
		for(int j=i*2;j<1000000;j+=i){
			prime[j]=false;
		}
	}

	while(cin>>n>>lm,n||lm){
		bool find = false;
		rep(i,100000){
			dp[i]=false;
		}
		dp[0] = 1;
		loop(i,0,n){
			cin>>dt[i];
			rep(j,lm){
				if(j + dt[i] > 1000000)continue;
				dp[j + dt[i]] |= dp[j];
			}
			
		}
		//rep(i,sizeof(okapon))if(okapon[i])cout<<i<<endl;
		for(int i = lm ; i >= 0 ; i --){
			if(i==1){cout<<"NA"<<endl;break;}
			if(dp[i] && prime[i]){cout<<i<<endl;break;}
		}
	}
}

C++: #include <stdio.h>

int n,m[30];
/*
bool prime[1000000];
*/
bool c[1000000];

void saiki(int total){
	int i;
	if(total<=0){
		return;
	}
	
	for( i=0 ; i<n ; i++){
		total-=m[i];
		if(c[total]==1)continue;
		if(total>=0){
			c[total]=1;
		}
		saiki(total);
	}
}

int check(int prime){
	int flg=0,i;
	if(prime%2==0)return 0;
	for(i=3;i<prime;i+=2){
		if(prime%i==0){
			flg=1;
		}
	}
	if(flg==1)return 0;
	return 1;
}

int main(void)
{
	int i,j;
	//f
	/*
	prime[0]=1;
	prime[1]=1;
	for(i=3;i<1000000;i++){
		if(i%2==0){
			prime[i]=1;
		}
	}
	for(i=3;i<1000000;i++){
		if(prime[i]==0){
			for(j=(i+i);j<1000000;j+=i){
				prime[j]=1;
			}
		}
	}
	*/
	//
	while(1){
		int x;
		int flg=0;
		scanf("%d%d",&n,&x);
		if(n==0)break;
		
		for(i=0;i<n;i++){
			scanf("%d",&m[i]);
		}
		saiki(x);
		//
		for(i=0;i<x;i++){
			
			if(c[i]==1 && check(x-i)){
				flg=1;
				break;
			}
		}
		if(flg==1){
			printf("%d\n",x-i);
		}
		else puts("NA");
		for(i=0;i<1000000;i++){
			c[i]=0;
		}
		//
	}
	
	
	return 0;
}

C++: #include <iostream>
using namespace std;
 
bool is_prime[1000000+1];
void prime(int n){
    for(int i=0;i<n+1;i++){
        is_prime[i] = true;
    }
    is_prime[0] = is_prime[1] = false;
    for(int i=2;i<n+1;i++){
        if(is_prime[i]==true){
            for(int j=i+i;j<n+1;j+=i){
                is_prime[j] = false;
            }
        }
    }
}
 
int main()
{
    int n,m;
    prime(1000000);
    while(cin >> n >> m){
        if(!n && !m)
            break;
        bool DP[1000000+1];
        for(int i=0;i<m+1;i++)
            DP[i] = false;
        DP[0] = true;
        int ryori;
        for(int i=0;i<n;i++){
            cin >> ryori;
            for(int j=0;j<m+1-ryori;j++)
                if(DP[j])
                    DP[j+ryori] = true;
        }       
         
        for(int i=m;i>=0;i--){
            if(is_prime[i] && DP[i]){
                cout << i << endl;
                break;
            }
            else if(i==0){
                cout << "NA" << endl;
                break;
            }
        }
    }
    return 0;
}

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

const int LIMIT = 1000000;

int
main(int argc, char* argv[]) {
	int i, j, n, x;
	int primes[LIMIT] = {0};
	int sums[LIMIT] = {0};

	// set primes
	primes[0] = 1;
	for (i = 2; i <= LIMIT/2; i++)
		for (j = 2; i*j <= LIMIT; j++)
			if (primes[i*j - 1] == 0)
				primes[i*j - 1] = 1;

	for ( ; ; ) {
		std::cin >> n >> x;
		if (n == 0 && x == 0)
			break;
		int *prices = new int(n);

		for (i = 0; i < n; i++) {
			std::cin >> prices[i];
			sums[prices[i] - 1] = 1;
		}

		for (i = 0; i < n; i++)
			for (j = 1; j < LIMIT; j++)
				if ((prices[i] + j + 1 <= LIMIT) && (sums[j]))
					sums[prices[i] + j] = 1;

		int max = 0;

		for (i = 0; i < x; i++)
			if (sums[i] && !primes[i])
				max = i + 1;

		if (max)
			std::cout << max << std::endl;
		else
			std::cout << "NA" << std::endl;
	}
	
	return 0;
}