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

bool isprime[1000001], dp[1000001];

void sieve()
{
	std::fill( isprime, isprime + 1000000, true );
	isprime[0] = isprime[1] = false;

	for( int i = 2; i <= 1000000; ++i )
		if( isprime[i] )
			for( int j = i * 2; j <= 1000000; j += i )
				isprime[j] = false;

	return;
}

int main()
{
	int n, x;

	sieve();

	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<bits/stdc++.h>
#define int long long
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
using namespace std;
int n, x;
bool b[1010000];
vector<int>prime;
signed main() {
	prime.push_back(2);
	for (int i = 3; i < 999999; i += 2) {
		bool b00l = 0;
		for (int p : prime) {
			if (i % p == 0) { b00l = 1; break; }
			if (p > sqrt(i))break;
		}
		if (!b00l)prime.push_back(i);
	}
	while (cin >> n >> x, n) {
		for1(i, x)b[i] = 0;
		b[0] = 1;
		for1(gr4cv, n) {
			int p; cin >> p;
			for0(i, x)if (i + p > x)break; else if (b[i])b[i + p] = 1;
		}
		int ans = -1;
		for (int p : prime)if (p > x)break; else if (b[p])ans = p;
		if (ans < 0)cout << "NA\n";
		else cout << ans << endl;
	}
}

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<stdio.h>
#include<bitset>
int main()
{
	const int N=1000001;
	static std::bitset<N>p,c;
	int i,j,n,x,a[30],f;
	p.set();
	p[0]=p[1]=0;
	for(i=2;i<N/2;++i)if(p[i])for(j=2*i;j<N;j+=i)p[j]=0;

	while(scanf("%d%d",&n,&x),n)
	{
		for(i=0;i<n;++i)scanf("%d",&a[i]);
		c.reset();
		c[0]=1;
		for(i=0;i<n;++i)
		{
			for(j=0;j+a[i]<=x;++j)
			{
				if(c[j]) c[ j+a[i] ]=1;
			}
		}
		f=0;
		for(i=x;i>=0;--i)
			if(c[i]&&p[i])
			{
				f=1,x=i;
				break;
			}
		if(f) printf("%d\n",x);
		else puts("NA");
	}
	return 0;
}

C++: #include<stdio.h>
long p,cnt,cnt2,food,g;
int n,d=0,kakaku[31],flag,youso[1000001]={0};
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()
{
	scanf("%d %ld",&n,&p);
	while(n!=0&&p!=0){
		for(cnt=1;cnt<=n;cnt++){
			scanf("%ld",&food);
			youso[food]=1;
			kakaku[cnt]=food;
		}
		for(cnt=1;cnt<=p;cnt++){
			if(youso[cnt]==1){
				for(cnt2=1;cnt2<=n;cnt2++){
					if(cnt+kakaku[cnt2]<=p){
						youso[cnt+kakaku[cnt2]]=1;
					}
				}
			}
		}
		for(cnt=p;cnt>0;cnt--){
			if(youso[cnt]==1){
				g=cnt;
				d=isPrime(g);
				if(d==1){
					flag=1;
					d=cnt;
					printf("%d\n",d);
					break;
				}
			}
		}
		if(flag==0){
			printf("NA\n");
		}
		d=0;
		flag=0;
		for(cnt=1;cnt<=p;cnt++){
			youso[cnt]=0;
		}
		scanf("%d %ld",&n,&p);
	}
	return 0;
}

C++: #include<iostream>
#include<vector>

using namespace std;

int main()
{
	char pri[1000000];
	int i,j;
	
	for(i=0;i<1000000;i++)
	{
		pri[i]='1';
	}
	pri[0]=pri[1]='0';
	
	for(i=0;i<1000000;i++)
	{
		if(pri[i]=='1')
		{
			for(j=2;j*i<1000000;j++)
			{
				pri[i*j]='0';
			}
		}
	}
	
	int n,max,menu[100];
	vector<char> sum;
	
	
	for(;;)
	{
		cin >> n >> max ;
		if(n==0 && max==0)
			break;
		int ans=0;
		sum.clear();
		for(i=0;i<1000000;i++)
			sum.push_back(0);
		
		for(i=0;i<n;i++)
		{
			cin >> menu[i];
			sum[menu[i]]='1';
		}
		for(i=0;i<=max;i++)
		{
//			cout << i << endl;
			if(sum[i]!='1')
			{
				for(j=0;j<i;j++)
				{
					if(sum[j]=='1' && sum[i-j]=='1')
					{
						sum[i]='1';
						if(pri[i]=='1')
							ans=i;
						break;
					}
				}
			}
		}
		
		if(ans==0)
			cout << "NA" << endl;
		else
			cout << ans << endl;
	}
}

C++: #include<iostream>
#include<vector>

using namespace std;

const int MAX=1000001;

void sieve(int MAX,bool prime[]){
	for(int i=0; i<=MAX; i++)	prime[i]=true;
	prime[0]=false;
	prime[1]=false;
	for(int i=2; i*i<=MAX; i++){
		if(prime[i])for(int j=i+i; j<=MAX; j+=i)prime[j]=false;
	}
}

int main(){
	bool prime[MAX+1];
	sieve(MAX,prime);
	int N,X;
	while(cin >> N >> X && N && X){
		int a[N];
		for(int i=0; i<N; i++)	cin>>a[i];
		vector<int> dp=vector<int>(X+1, 0);
		int ans=-1;
		for(int i=0; i<N; i++){
			for(int j=1; j<=X; j++){
				if(j>=a[i]){
					dp[j]=max(dp[j],dp[j-a[i]]+a[i]);
					if(prime[dp[j-a[i]]+a[i]])	ans=max(ans,dp[j-a[i]]+a[i]);
				}
			}
		}
		if(ans>0)	cout << ans << endl;
		else		cout << "NA" << endl;
	}
}

C++: #include<stdio.h>
int hideo[1000001] = { 0 }, ruio[31] = { 0 };
int main()
{
	int  n, x, temp = 1,noyori=0,debu=0 ;
	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 (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++;
					}
				}
				if (debu == 0) {
					noyori = i;
					break;
				}
			}
			debu = 0;
		}
		if (noyori > 0) {
			printf("%d\n", noyori);
		}
		else {
			printf("NA\n");
		}
		temp = 1;
		noyori = debu = 0;
		for (int i = 1; i <= n; i++) {
			ruio[i] = 0;
		}
		for (int i = 1; i <= x; i++) {
			hideo[i] = 0;
		}
	}
	return 0;
}