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++: // 0202_AtBosssExpense.cpp
//
#include <bits/stdc++.h>
using namespace std;
const int MAX_X = 1000001;
const int MAX_N =30;
bool prime[MAX_X], dp[MAX_X];
int v[MAX_N];
int n, x;
void table() {
  fill(prime,prime+MAX_X,1);

  for(int i=2;i*i<MAX_X;++i)
    if(prime[i])
      for(int j=i*i;j<MAX_X;j+=i)
        prime[j]=0;
}
void solve() {
  fill(dp,dp+MAX_X,0);
  dp[0]=1;
  for(int i=0;i<=x;++i)
    for(int j=0;j<n;++j)
      if(v[j]<=i&&dp[i-v[j]]) dp[i]=1;

  for(int i=x;i>0;--i) {
    if(prime[i]&&dp[i]) {
      cout << i << endl;
      return;
    }
  }
  cout << "NA" << endl;
}
int main() {
  table();
  while(cin >> n >> x && n && x) {
    for(int i=0;i<n;++i) cin >> v[i];
    solve();
  }
  return 0;
}

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

constexpr int MAX_N = 30, MAX_C = 1000001;
int n, max;
int cost[MAX_N];
int dp[MAX_C];
bool prime_num[MAX_C];

int main() {
	while (1) {
		std::cin >> n >> max;
		if (n + max == 0)
			break;
		std::memset(prime_num, false, sizeof(prime_num));
		std::memset(dp, 0, sizeof(dp));
		for (int i = 0; i < n; ++i)
			std::cin >> cost[i];
		for (int i = 2; i * i <= max; ++i) {
			if (!prime_num[i]) {
				for (int j = 2; i*j <= max; ++j)
					prime_num[i*(j + 2)] = true;
			}
		}
		for (int i = 0; i < n; ++i)
			dp[cost[i]] = cost[i];
		int ans = 0;
		for (int i = 1; i <= max; ++i) {
			dp[i] = dp[i - 1];
			for (int j = 0; j < n; ++j) {
				if (i > cost[j])
					dp[i] = std::max(dp[i], dp[i - cost[j]] + cost[j]);
			}
			if (!prime_num[dp[i]])
				ans = dp[i];
		}
		if (!prime_num[max])
			ans = max;
		if (!ans)
			std::cout << "NA" << std::endl;
		else
			std::cout << ans << std::endl;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <fstream>
#include <sstream>
#include <cstring>
using namespace std;
typedef long long ll;

int n, x;
int ps[40];

bool isp[1000010];
void sieve(){
    const int N = 1000000;
    memset(isp, true, sizeof(isp));
    
    isp[0] = false;
    isp[1] = true;
    
    for(int p=2;p*p<=N;p++)if(isp[p]){
        for(int j=p*p;j<=N;j+=p)isp[j] = false;
    }
}

bool can[1000010];
void gen(){
    memset(can, false, sizeof(can));
    can[0] = true;
    
    for(int sum=0;sum<x;sum++){
        for(int i=0;i<n;i++){
            if(sum + ps[i] <= x){
                can[sum + ps[i]] |= can[sum];
            }
        }
    }
}


int main(){
    sieve();
    
    while(cin >> n >> x){
        if(n == 0 && x == 0)break;
        
        for(int i=0;i<n;i++)cin >> ps[i];
        gen();
    
        int res = -1;
        for(int sum=x;sum>=2;sum--)if(can[sum] && isp[sum]){
            res = sum;
            break;
        }
        
        if(res == -1){
            cout << "NA" << endl;
        } else {
            cout << res << endl;
        }
    }
    
    return 0;
}

C++: #include<stdio.h>
#include<string.h>
#include<math.h>
long long int a,s,d[1000001],f,g[10000001],h[1000001];
int main(void)
{
	int j,i,k;
	for(i=0;i<1000001;i++){
		h[i]=0;
		g[i]=0;
	}
	for(i=2;i*i<=1000000;i++){
		if(h[i]==0){
			for(j=2;j<=500000;j++){
				if(i*j>1000000) break;
				h[i*j]=1;
			}
		}
	}
	while(1){
		scanf("%d %d",&a,&s);
		f=0;
		if(a==0&&s==0) break;
		for(i=0;i<1000001;i++) g[i]=0;
		for(i=0;i<a;i++){
			scanf("%d",&d[i]);
			g[d[i]]=1;
		}
		for(i=0;i<=s;i++){
			if(g[i]==1){
				for(j=0;j<a;j++){
					if(i+d[j]<=s) g[i+d[j]]=1;
				}
			}
		}
		for(i=s;i>1;i--){
			if(h[i]==0&&g[i]==1){
				f=i;
				break;
			}
		}
		if(f==0) printf("NA\n");
		else printf("%d\n",f);
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

bool flag[1000001];
int n, x, m, price[30];

bool sosuu(int k) {
	if (k == 2) return true;
	else if (k % 2 == 0) return false;
	for (int i = 3; i*i<=k; i += 2)
		if (k % i == 0) return false;
	return true;
}
void next(int p, int k) {
	if (flag[k]) return;
	flag[k] = true;
	if (k > x) return;
	if (k > m) if (sosuu(k)) m = k;
	if (p == n) return;
	for (int i = 0; k + price[p] * i <= x; ++i)
		next(p + 1, k + price[p] * i);
}

int main() {
	while (cin >> n >> x, n || x) {
		for (int i = 0; i < 1000001; ++i) flag[i] = false;
		for (int i = 0; i < n; ++i)
			cin >> price[i];
		m = 0;
		next(0, 0);
		if (m) cout << m << endl;
		else cout << "NA" << endl;
	}
}

C++: #include <iostream>
#include <cmath>
#define MAX 1000000

using namespace std;

bool prime[MAX+1];

void eratos(){
  for(int i=0;i<=MAX;i++) prime[i]=false;
  for(int i=3;i<=MAX;i+=2) prime[i]=true;
  prime[2]=true;
  int limit=(int)sqrt((double)MAX)+1;
  for(int i=3;i<=limit;i+=2){
    if(!prime[i]) continue;
    for(int j=i+i;j<=MAX;j+=i){
      prime[j]=false;
    }
  }
}

main(){
  eratos();
  int n, x;
  while(1){
    cin >> n >> x;
    if(n==0 && x==0) break;

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

    int max=-1;

    bool can[MAX+1];
    for(int i=0;i<=x;i++) can[i]=false;
    can[0]=true;
    for(int i=0;i<=x;i++){
      if(can[i]){
	int tmp;
	for(int j=0;j<n;j++){
	  tmp=i+items[j];
	  if(tmp<=x){
	    can[tmp]=true;
	  }
	}
      }
    }
    for(int i=x;i>=0;i--){
      if(i==0) cout << "NA" << endl;
      if(can[i] && prime[i]){
	cout << i << endl;
	break;
      }
    }
  }
  return 0;
}

C++: #include<vector>
#include<iostream>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
#define ALL(C)     (C).begin(),(C).end()

const int N = 1000001;
const int M = 30;

bool table[M][N];
bool isprime[N];

void generate(){
  for(int i=0;i<N;i+=2)isprime[i]=false;
  for(int i=1;i<N;i+=2)isprime[i]=true;
  isprime[2]=true;
  for(int i=3;i*i <= N ;i+=2){
    if (isprime[i]){
      for(int j=2*i;j<N;j+=i)isprime[j]=false;
    }
  }
}

void solve(int n,int lim,vector<int> & price){
  rep(i,n)rep(j,lim+1)table[i][j]=false;
  
  for(int i=0;i<lim+1;i+=price[0]){
    table[0][i]=true;
  }

  REP(i,1,price.size()){
    rep(j,lim+1){
      table[i][j]=table[i-1][j];
      if (j-price[i] < 0)continue;
      table[i][j]|=(table[i][j-price[i]]);
    }
  }

  for(int i=lim;i>0;i--){
    if (isprime[i] && table[n-1][i]){
      cout << i << endl;
      return;
    }
  }
  cout << "NA" << endl;
}


main(){
  int n;
  int lim;
  generate();
  while(cin>>n>>lim && n){
    vector<int> a;
    int tmp;
    rep(i,n){
      cin>>tmp;
      a.push_back(tmp);
    }
    solve(n,lim,a);
  }
  return false;
}