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<stdio.h>
#include <string.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 p,cnt,cnt2,food;
int n,d=0,g,kakaku[31],flag,youso[1000002]={0};
int main()
{
	scanf("%d %d",&n,&p);
	while(1){
		//memset(youso, 0, sizeof(youso));
		for(int i=0;i<p+1;i++){
			youso[i]=0;
		}
		if(n==0&&p==0){
			break;
		}
		for(cnt=1;cnt<=n;cnt++){
			scanf("%d",&food);
			youso[food]=1;
			kakaku[cnt]=food;
		}
		for(cnt=0;cnt<=p;cnt++){
			if(youso[cnt]==1){
				for(cnt2=1;cnt2<=n;cnt2++){
					if(cnt+kakaku[cnt2]<=p){
						youso[cnt+kakaku[cnt2]]=1;
					}
				}
			}
		}
		flag=0;
		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;
		
		scanf("%d %d",&n,&p);
	}
	return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstring>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)
#define all(n) n.begin(),n.end()

const int MAXN = 1000 * 1000 + 10;

bool p[MAXN];
bool ok[MAXN];

int main()
{
    p[0] = p[1] = 1;
    REP(MAXN)if(!p[i])for(int j = i*2;j<MAXN;j+= i)p[j] = 1;

    int n, x;
    while(cin >> n >> x && n)
    {
        memset(ok, 0, sizeof(ok));
        vector<int> dish;
        int t = 0;

        REP(n) {cin >> t; dish.push_back(t); ok[t] = 1;}

        sort(all(dish));
        //REP(n) cout << "d" << i << " " << dish[i] << endl;

        rep(j,x+1)if(ok[j])REP(n)for(int k = j+dish[i];k<x+1;k+=dish[i])ok[k] = 1;

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

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

    return 0;
}

C++: #include<cstdio>
bool dp[1000001];
bool isprime(int& x){
  if(x > 2 && x % 2 == 0) return true;
  for(int i = 3 ; i * i <= x ; i += 2 ) if( x % i == 0) return true;
  return x == 1;
}
int solve(int& i){
  while(true){
    if(dp[i] && !isprime(i)) return i;
    i--;
  }
}
int main(){
  int n,x,data,ans;
  dp[0] = true;
  while(scanf("%d %d",&n,&x) , n){
    for(int i = 1 ; i <= x ; i++ ) dp[i] = false;
    for(int i = 0 ; i < n ; i++ ){
      scanf("%d",&data);
      for(int i = data ; i <= x ; i++ ) if(dp[i-data]) dp[i] = true;
    }
    if(ans = solve(x)) printf("%d\n",ans);
    else printf("NA\n");
  }
}

C++: #include<iostream>
#include<algorithm>
#define rep(i,n) for(int i=0;i<n;i++)
#define MP 10000001
using namespace std;
bool p[MP]; int n,x,c[35],ans;
bool rec(int a,int s){
	int f=0;
	for(int i=s;i>=0;i--)if(i==n-1||c[i]!=c[i+1])if(a>=c[i]){
		if(a==c[i])return 1;
		else{
			f=rec(a-c[i],i);
			if(f) return 1;
		}
	}
	return 0;
}
int main(){
	for(int i=2;i*i<MP;i++)if(!p[i])for(int j=i+i;j<MP;j+=i)p[j]=1;
	p[0]=p[1]=1;
	while(cin>>n>>x,n){
		rep(i,n)cin>>c[i]; sort(c,c+n);
		for(ans=x;ans>=c[0];ans--)if(!p[ans]&&rec(ans,n-1))break;
		if(ans<c[0])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<100000;i++){
		for(int j=i*2;j<100000;j+=i){
			prime[j]=false;
		}
	}

	while(cin>>n>>lm,n||lm){
		bool find = false;
		rep(i,100000){
			dp[i]=false;
		}
		dp[0] = 1;
		int m = 0 ; 
		loop(i,0,n){
			cin>>dt[i];
			rep(j,lm){
				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==2){cout<<"NA"<<endl;break;}
			if(dp[i] && prime[i]){cout<<i<<endl;break;}
		}
	}
}

C++: #include<iostream>
#define N 1000001
using namespace std;
int main(){
  int p[N]={0};
  for(int i=3;i<N;i+=2) p[i] = 1;
  p[2] = 1;
  for(int i=3;i<=1000;i+=2){
    if(p[i]==1){
      for(int j=2*i;j<N;j+=i) p[j] = 0;
    }
  }
  int n,x;
  while(cin >> n >> x){
    if(n==0&&x==0) break;
    int t[x+1];
    for(int i=0;i<=x;i++) t[i] = 0;
    for(int i=0;i<n;i++){
      int k;
      cin >> k;
      if(k<=x) t[k] = 1;
      for(int j=1;j<=x;j++){
	if(t[j]==1&&j+k<=x) t[j+k] = 1;
      }
    }
    bool ok = false;
    for(int i=x;i>=0;i--){
      if(t[i]==1&&p[i]==1){
	cout << i << endl;
	ok = true;
	break;
      }
    }
    if(!ok) cout << "NA" << endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define INF 1e9


int main(){
    int N = 10e6+1;
    vector<bool> isPrime(N, true);
    isPrime[0] = isPrime[1] = false;
    for (int i = 2; i*i < N; i++) {
        if (!isPrime[i]) continue;
        for (int j = i*i; j < N; j += i) isPrime[j] = false;
    }
    while(true){
        int n,x;
        cin >> n >> x ;
        if(n == 0 && x == 0){
            break;
        }

        vector<int> dishes(n,0);

        FOR(i,0,n){
            cin >> dishes[i];
        }
        int ans = 0;
        vector<bool> dp(x+1,false);
        dp[0] = true;

        for(auto dish:dishes){
            FOR(i,0,x+1){
                if((i+dish < x+1) && dp[i]){
                    if(isPrime[i+dish])
                       ans = i + dish;
                    dp[i+dish] = true;
                }
            }
        }
        if(ans == 0)
            cout << "NA" << endl;
        else
            cout << ans << endl;
    }
    return 0;
}

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

const int MAX_X = 1000000;
bool sosu[MAX_X+1];
bool sum[MAX_X+1];
int costs[30];

int main(){
	for(int i = 2; i <= MAX_X; i++) sosu[i] = true;
	for(int i = 2; i * i <= MAX_X; i++){
		if(sosu[i] == true)
			for(int j = 2; i * j <= MAX_X; j++)
				sosu[i*j] = false;
	}
	sosu[0] = sosu[1] = false;
	int n, x;
	while(cin >> n >> x){
		if(n == 0 && x == 0) break;
		for(int i = 1; i <= x; i++){
			sum[i] = false;
		}
		sum[0] = true;
		for(int i = 0; i < n; i++){
			cin >> costs[i];
		}
		for(int i = 0; i < x; i++){
			if(sum[i])
				for(int j = 0; j < n; j++){
					if(i + costs[j] <= x)
						sum[i+costs[j]] = true;
				}
		}
		int m = x;
		while(m > 1){
			if(sum[m] && sosu[m]) break;
			m--;
		}
		if(m == 1) cout << "NA" << endl;
		else cout << m << endl;
	}
	return 0;
}