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++: // AOJ 0202
#include<iostream>
#include<cstring>

int ps[30];
bool dp[1000001];

bool isprime( int n )
{
	for( int i = 2; i * i <= n; ++i )
		if( n % i == 0 )
			return false;

	return n != 1;
}

int main()
{
	int n, x;
	while( std::cin >> n >> x, n | x )
	{
		memset( dp, false, sizeof( dp ) );
		dp[0] = true;

		int ans = 0;
		for( int i = 0; i != n; ++i )
		{
			int p;
			std::cin >> p;

			for( int j = p; j <= x; ++j )
			{
				if( dp[j-p] )
				{
					dp[j] = true;
					if( isprime( j ) )
						ans = std::max( ans, j );
				}
			}
		}

		if( ans )
			std::cout << ans << std::endl;
		else
			std::cout << "NA" << std::endl;
	}

	return 0;
}

C++: #include<stdio.h>
int isPrime(int x){
	int i;
	if(x<2) return 0;
	else if(x==2) return 1;
	if(x%2==0) return 0;
	for(i=3;i*i<=x;i+=2){
		if(x%i==0) return 0;
	}
	return 1;
}
int main()
{
	long cnt,cnt2,food;
	int n,x,d=0,g,kakaku[31],youso[1000001]={0};
	int flag=0;
	scanf("%d %d",&n,&x);
	while(n!=0&&x!=0){
		for(cnt=1;cnt<=n;cnt++){
			scanf("%ld",&food);
			youso[food]=1;
			kakaku[cnt]=food;
		}
		for(cnt=1;cnt<=x;cnt++){
			if(youso[cnt]==1){
				for(cnt2=1;cnt2<=n;cnt2++){
					youso[cnt+kakaku[cnt2]]=1;
					if(cnt+kakaku[cnt2]>x){
						break;
					}
				}
			}
		}
		for(cnt=x;cnt>0;cnt--){
			if(youso[cnt]==1){
				g=cnt;
				d=isPrime(g);
				if(d==1){
					d=cnt;
					flag=1;
					printf("%d\n",d);
					break;
				}
			}
		}
		if(flag==0){
			printf("NA\n");
		}
		flag=0;
		d=0;
		for(cnt=1;cnt<=x;cnt++){
			youso[cnt]=0;
		}
		scanf("%d %d",&n,&x);
	}
	return 0;
}

C++: #include<iostream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

bool prime[1000001];

int main(){
	int n,x;
	rep(i,1000002)prime[i]=true;
	prime[0]=prime[1]=false;
	loop(i,2,1010)for(int j=i*2;j<1000001;j+=i)prime[j]=false;
	while(cin>>n>>x,n||x){
		int dish[n];
		rep(i,n)cin>>dish[i];
		bool cost[x+10];
		rep(i,x+10)cost[i]=false;
		rep(i,n)cost[dish[i]]=true;
		cost[0]=true;
		rep(i,x+1){
			if(!cost[i])continue;
			rep(j,n){
				if(i+dish[j]>x)continue;
				cost[i+dish[j]]=true;
			}
		}
		bool check=true;
		for(int i=x;i>=0;i--){
			if(prime[i] && cost[i]){
				check=false;
				cout<<i<<endl;
				break;
			}
		}
		if(check)cout<<"NA"<<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <cmath>
#include <queue>
#include <functional>

using namespace std;

int main() {
	int n, x;
	vector<int> furui(1000000+1, 0);
	furui[0] = furui[1] = 1;
	for (int i = 2; i*i <= 1000000; i++) {
		if (furui[i] == 0) {
			for (int j = 2; i*j <= 1000000; j++) {
				furui[i*j] = 1;
			}
		}
	}
	while (cin >> n >> x) {
		if (n == 0 && x == 0) {
			break;
		}
		vector<int> en;
		priority_queue<int, vector<int>, greater<int> > pq;
		vector<int> dp(x+1, 0);
		for (int i = 0; i < n; i++) {
			int k;
			cin >> k;
			if (k > x || k == 0) {
				continue;
			}
			dp[k] = 1;
			pq.push(k);
		}/*
		en.push_back(pq.top());
		pq.pop();
		while (!pq.empty()) {
			int k = pq.top();
			pq.pop();
			bool hantei2 = true;
			for (int i = 0; i < en.size(); i++) {
				if (k % en[i] == 0) {
					hantei2 = false;
					break;
				}
			}
			if (hantei2) {
				en.push_back(k);
			}
		}
		for (int i = 0; i < en.size(); i++) {
			for (int j = 0; j <= x; j++) {
				if (j < en[i]) {
				} else {
					dp[j] = max(dp[j], dp[j-en[i]]);
				}
			}
		}
		bool hantei = true;
		for (int i = x; i >= 0; i--) {
			if (dp[i] > 0 && furui[i] == 0) {
				cout << i << endl;
				hantei = false;
				break;
			}
		}
		if (hantei) {
			cout << "NA" << endl;
		}*/
	}
	return 0;
}

C++: #include<stdio.h>
#include<string.h>
#include<iostream>
int hideo[2000001] = { 0 };
int main(void)
{
	int noyori = 0, debu = 0, n, temp = 1, ruio[32] = { 0 }, x;
	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;
		memset(ruio, 0, sizeof(ruio));
		memset(hideo, 0, sizeof(hideo));
	}
	return 0;
}

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

int n, x;
int a[30];
int dp[1000001];
int prime[1000001];

int main(){
	for(int i=0; i<1000001; i++){
		prime[i] = 1;
	}
	prime[0] = 0;
	prime[1] = 0;
	prime[2] = 1;
	for(int i=0; i<1000001; i++){
		if(prime[i]==1){
			for(int j=i+i; j<1000001; j+=i){
				prime[j] = 0;
			}
		}
	}


	for(;;){
		cin >> n >> x;
		if(n==0&&x==0) break;
		for(int i=0; i<n; i++){
			cin >> a[i];
		}

		for(int i=0; i<=x; i++){
			dp[i] = 0;
		}
		dp[0] = 1;

		for(int i=0; i<=x; i++){
			for(int j=0; j<n; j++){
				if(i-a[j]>=0){
					if(dp[i-a[j]]==1){
						dp[i] = 1;
					}
				}
			}
		}
		int mx = 0;
		for(int i=0; i<=x; i++){
			if(dp[i]==1 && prime[i]==1) mx = i;
		}

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

	return 0;
}

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 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 && prime[x-i]==0){
				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;
}