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 <iostream>
#include <cstring>
using namespace std;

#define MAXNUM 1000001

bool prime[MAXNUM];

void eratosthenes()
{
	prime[0]=prime[1]=false;

	for(int i=2; i<MAXNUM; i++)
	{
		prime[i]=true;
	}
	
	for(int i=2; i*i<MAXNUM; i++)
	{
		if(prime[i])
		{
			for(int j=i*i; j<MAXNUM; j+=i)
			{
				prime[j]=false;
			}
		}
	}
}


bool dp[1000001];

int main()
{
	eratosthenes();
	int N,B,c[30];
	while(cin >> N >> B)
	{
		memset(dp,0,sizeof(dp));
		for(int i=0; i<N; i++)
			cin >> c[i];
			
		dp[0]=1;
		
		for(int i=0; i<N; i++)
		for(int j=0; j<B; j++)
		{
			if(j+c[i]>B) break;
			if(dp[j]) dp[j+c[i]]=1;
		}
		
		bool g=false;
		for(int i=B; i>1; i--)
		{
			if(dp[i]&&prime[i])
			{
				g=true;
				cout << i << endl;
				break;
			}
		}
		if(!g) cout << "NA" << endl;
	}
}

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

int sosuu( int a )
{
	if( a < 2 )
	{
		return 0 ;
	}
	else if( a == 2 )
	{
		return 1 ;
	}
	if( a % 2 == 0 )
	{
		return 0 ;
	}
	for( int i = 3 ; i * i <= a ; i += 2 )
	{
		if( a % i == 0 )
		{
			return 0 ;
		}
	}
	return 1 ;
}

int main()
{
	int n ,m ;
	int dmon[ 30 ] ;
	int tmp ;
	while( scanf( "%d %d", &n , &m ), n != 0 )
	{
		for( int i = 0 ; i < n ; i++ )
		{
			cin >> dmon[ i ] ;
			for( int j = 0 ; j < i ; j++ )
			{
				if( dmon[ i ] < dmon[ j ] )
				{
					tmp = dmon[ i ] ;
					dmon[ i ] = dmon[ j ] ;
					dmon[ j ] = tmp ;
				}
			}
		}
		int i ;
		int dp[ 1000000 ] = { 0 } ;
		for( i = 0 ; i + dmon[ 0 ] <= m ; )
		{
			for( int j  = 0 ; j < n ; j++ )
			{
				dp[ i + dmon[ j ] ] = 1 ;
			}
			do
			{
				i++ ;
			}while( dp[ i ] != 1 && i <= m ) ;
		}
		for( int i = m ; i >= 0 ; i-- )
		{
			while( dp[ i ] != 1 )
			{
				i-- ;
			}
			if( tmp = sosuu( i ) > 0 )
			{
				cout << i << endl ;
				goto NEXT ;
			}
		}
		cout << "NA" << endl ;
		NEXT : ;
	}
	return 0 ;
}

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

const int MAX = 1000000;

int main() {
  static bool is_prime[MAX + 1];
  fill(is_prime, is_prime + MAX + 1, true);
  is_prime[0] = is_prime[1] = false;
  for(int i = 2; i * i <= MAX; ++i)
    for(int j = i * i; j <= MAX; j += i)
      is_prime[j] = false;
  for(int N, S; cin >> N >> S, N || S; ) {
    static bool can_make[MAX + 1];
    fill(can_make, can_make + MAX + 1, false);
    can_make[0] = true;
    for(int i = 0; i < N; ++i) {
      int x; cin >> x;
      for(int j = 0; j <= S - x; ++j) {
        if(can_make[j]) can_make[j + x] = true;
      }
    }
    int ans = -1;
    for(int i = (int)S; i >= 0; --i) {
      if(can_make[i] && is_prime[i]) {
        ans = i;
        break;
      }
    }
    if(ans == -1) cout << "NA" << endl;
    else cout << ans << 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 = 0;
		debu = 0;
		for (int i = 1; i <= n; i++) {
			ruio[i] = 0;
		}
		for (int i = 1; i <= x; i++) {
			hideo[i] = 0;
		}
	}
	return 0;
}

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;
}

Compile Error Logs:

ステータス
Judge: 1/1	C++	CPU: 00:92 sec	Memory: 8976 KB	Length: 679 B	2014-01-07 17:45
テストケースの判定結果
Case #	Verdict	CPU Time	Memory	In	Out	Case Name
Case #1	: Accepted	00:92	8976	0	0	judge_data

< prev |		/		| next >	 		
 
Judge Input #  ( | )		Judge Output #  ( | )

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

constexpr int MAX_X = 1000001;
constexpr int MAX_N = 31;

int n, x, values[MAX_N];
bool is_prime_number[MAX_X] = {true};

void initialize();

void solve();

int main(){
    initialize();
    while(true){
        std::cin >> n >> x;
        
        if(n + x == 0) break;
        
        for(int i = 0; i < n; ++i)
            std::cin >> values[i];

        solve();
    }
}

void initialize(){
    for(int i = 0; i <= MAX_X; ++i) is_prime_number[i] = true;
    is_prime_number[0] = false, is_prime_number[1] = false;
    for(int i = 2; i * i <= MAX_X; ++i){
        if(is_prime_number[i]){
            for(int j = i + 1; j < MAX_X; ++j){
                if(j % i == 0)
                    is_prime_number[j] = false;
            }
        }
    }
}

void solve(){
    int ans = -1;
    int dp[MAX_X];
    memset(dp, 0, x);

    for(int i = 1; i <= x; ++i){
        int res = -1;
        for(int j = 0; j < n; ++j){
            if(values[j] <= i){
                res = std::max(dp[i - values[j]] + values[j], res);
            }
        }
        dp[i] = std::max(dp[i], res);
        if(is_prime_number[dp[i]]){
            ans = std::max(dp[i], ans);
        }
    }

    if(ans != -1){
        std::cout << ans << std::endl;
    }
    else{
        std::cout << "NA" << std::endl;
    }
}

C++: #include<iostream>
using namespace std;
bool p[1000000] = { false };
void prime();
int main()
{	prime();
while (true){
	bool dp[1000001] = { false };
	int a[31];
	int n, v;
	cin >> n >> v;
	if (n == 0){
		break;
	}
	for (int i = 0; i < n; i++){
		cin >> a[i];
	}
	dp[0] = true;
	for (int i = 0; i < n; i++){
		for (int i2 = 0; i2 < v - a[i]; i2++){
			if (dp[i2]){
				dp[i2 + a[i]] = true;
			}
		}
	}

	bool flag = true;
	for (int i = 1000000; i > 0; i--){
		if (dp[i] && !p[i]){
			flag = false;
			cout << i << endl;
			break;
		}
	}
	if (flag)
		cout << "NA" << endl;
}

}
void prime(){
	for (int i = 2; i < 100000; i++){
		for (int i2 = 2; i2*i < 100000; i2++){
			if (!p[i2*i]){
				p[i2*i] = true;
			}
		}
	}
}