alexjercan/bugnet huggingface dataset:
Problem p00202 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define sint(i) scanf("%d", &i);
#define sintt(i, j) scanf("%d%d", &i, &j);
#define sinttt(i, j, k) scanf("%d%d%d", &i, &j, &k);
#define sintttt(i, j, k, m) scanf("%d%d%d%d", &i, &j, &k, &m);

#define INF 1010000000
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

char sosu[1000001];
char can[1000001];

int main() {
  rep(i, 1000001) { sosu[i] = 0; }

  sosu[0] = 1;
  sosu[1] = 1;

  rep(i, 1000001) {
    if (sosu[i] == 1)
      continue;
    for (int j = i + i; j < 1000001; j += i) {
      sosu[j] = 1;
    }
  }

  while (1) {
    int n, m;
    sintt(n, m);
    if (n == 0)
      break;

    rep(i, 1000001) { can[i] = 0; }

    int sina[31];
    rep(i, n) { sint(sina[i]); }

    can[0] = 1;
    reps(i, m) {
      rep(j, n) {
        if (i - sina[j] < 0) {
          continue;
        }
        if (can[i - sina[j]] == 1) {
          can[i] = 1;
        }
      }
    }

    int ans = -1;
    for (int i = m; i >= 0; i--) {
      if (!sosu[i] & can[i] == 1) {
        ans = i;
        break;
      }
    }

    if (ans == -1) {
      puts("NA");
    } else {
      printf("%d\\n", ans);
    }
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>

#define sint(i) scanf("%d", &i);
#define sintt(i, j) scanf("%d%d", &i, &j);
#define sinttt(i, j, k) scanf("%d%d%d", &i, &j, &k);
#define rep(i, n) for (int i = 0; i < n; i++)

using namespace std;

int n, m;
int sina[301];
char memo[1000002];
char sosu[1000002];
char roop[1000002];

char N(int val) {
  if (val < 0 || val > 1000000) {
    return 0;
  }

  if (val == 0) {
    return 1;
  }

  if (memo[val] != -1) {
    return memo[val];
  }

  for (roop[val] = 0; roop[val] < n; ++roop[val]) {
    if (N(val - sina[roop[val]]) == 1) {
      return memo[val] = 1;
    }
  }

  return memo[val] = 0;
}

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

  while (1) {
    sintt(n, m);
    if (n == 0)
      break;
    rep(i, n) { sint(sina[i]); }

    rep(i, 1000001) { memo[i] = -1; }

    int flg = 1;
    int ans = 0;

    for (int i = m; i > 0; i--) {
      if (sosu[i] != 0) {
        continue;
      }

      if (N(i) == 1) {
        ans = i;
        flg = 0;
        break;
      }
    }

    /*
    rep(i,m){
            if(memo[i]==0){
                    printf("%d\\n",i);
            }
    }*/

    if (flg == 1) {
      puts("NA");
    } else {
      printf("%d\\n", ans);
    }
  }
}
Problem p00202 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>

using namespace std;

#define rep(i, n) for (int i = 0; i < n; i++)
#define reps(i, n) for (int i = 1; i <= n; i++)

int sosu[1111111];
int dp[1211111];
int main() {

  sosu[0] = 1;
  sosu[1] = 1;

  for (int i = 2; i < 1111111; i++) {
    if (sosu[i] == 1)
      continue;
    for (int j = i + i; j < 1111111; j += i) {
      sosu[j] = 1;
    }
  }

  while (1) {
    int n, m;
    cin >> n >> m;
    if (n == 0)
      break;

    rep(i, 1111111) dp[i] = 0;
    dp[0] = 1;

    int item[33];
    rep(i, n) { cin >> item[i]; }

    int ans = -1;
    rep(i, m + 1) {
      if (dp[i] == 0)
        continue;
      if (sosu[i] == 0)
        ans = i;
      rep(j, n) {
        if (i + item[j] > m)
          continue;
        dp[i + item[j]] = 1;
      }
    }
    if (ans == -1) {
      puts("NA");
    } else {
      printf("%d\\n", ans);
    }
  }
}

Error: 0

Fixed submission:

#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>

using namespace std;

#define rep(i, n) for (int i = 0; i < n; i++)
#define reps(i, n) for (int i = 1; i <= n; i++)

int sosu[1111111];
int dp[1211111];
int main() {

  sosu[0] = 1;
  sosu[1] = 1;

  for (int i = 2; i < 1111111; i++) {
    if (sosu[i] == 1)
      continue;
    for (int j = i + i; j < 1111111; j += i) {
      sosu[j] = 1;
    }
  }

  while (1) {
    int n, m;
    cin >> n >> m;
    if (n == 0)
      break;

    rep(i, 1111111) dp[i] = 0;
    dp[0] = 1;

    int item[33];
    rep(i, n) { cin >> item[i]; }

    int ans = -1;
    rep(i, m + 1) {
      if (dp[i] == 0)
        continue;
      if (sosu[i] == 0)
        ans = i;
      rep(j, n) { dp[i + item[j]] = 1; }
    }
    if (ans == -1) {
      puts("NA");
    } else {
      printf("%d\\n", ans);
    }
  }
}
Problem p00202 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define shosu(n) setprecision(n)
#define INF 999999999
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef vector<vb> vvb;
typedef vector<vpii> vvpii;
bool sosu(int n) {
  if (n <= 1)
    return false;
  for (int i = 2; i * i <= n; i++)
    if (n % i == 0)
      return false;
  return true;
}
int main() {
  int n, x;
  while (cin >> n >> x, n) {
    bool dp[1000001] = {};
    dp[0] = 1;
    int a[50];
    rep(i, n) { cin >> a[i]; }
    rep(i, n) rep(j, x) {
      if (j + a[i] < 1000001)
        if (dp[j])
          dp[j + a[i]] = 1;
    }
    for (int i = x; i > 1; i--) {
      if (dp[i])
        if (sosu(i)) {
          cout << i << endl;
          goto end;
        }
    }
    cout << "NA" << endl;
  end:;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define shosu(n) setprecision(n)
#define INF 999999999
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef vector<vb> vvb;
typedef vector<vpii> vvpii;
bool sosu(int n) {
  if (n <= 1)
    return false;
  for (int i = 2; i * i <= n; i++)
    if (n % i == 0)
      return false;
  return true;
}
int main() {
  int n, x;
  while (cin >> n >> x, n) {
    bool dp[1000001] = {};
    dp[0] = 1;
    int a[50];
    rep(i, n) { cin >> a[i]; }
    rep(i, n) rep(j, x) {
      if (dp[j])
        dp[j + a[i]] = 1;
    }
    for (int i = x; i > 1; i--) {
      if (dp[i])
        if (sosu(i)) {
          cout << i << endl;
          goto end;
        }
    }
    cout << "NA" << endl;
  end:;
  }
  return 0;
}
Problem p00202 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#define rep(i, n) for (int i = 0; i < n; i++)
#define MP 1000001
using namespace std;
bool p[MP], a[MP];
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;
  int c[30], n, x, ans;
  while (cin >> n >> x, n) {
    fill(a, a + x + 1, 0);
    rep(i, n) cin >> c[i];
    ans = 0, a[0] = 1;
    rep(i, x + 1) rep(j, n) if (i >= c[j] && a[i - c[j]]) {
      a[i] = 1;
      if (!p[i])
        ans = i;
    }
    if (ans)
      cout << ans << endl;
    else
      cout << "NA" << endl;
  }
  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <iostream>
#define rep(i, n) for (int i = 0; i < n; i++)
#define MC 1000001
using namespace std;
int p[MC], V[MC];
int n, x, c[35], ans;
void rec(int a) {
  rep(i, n) if (a + c[i] < x && !V[a + c[i]]) V[a + c[i]] = 1, rec(a + c[i]);
}
int main() {
  for (int i = 2; i * i < MC; i++)
    if (!p[i])
      for (int j = i + i; j < MC; 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);
    fill(V, V + x, 0);
    rec(0);
    for (ans = x; ans >= c[0]; ans--)
      if (!p[ans] && V[ans])
        break;
    if (ans < c[0])
      cout << "NA" << endl;
    else
      cout << ans << endl;
  }
  return 0;
}
Problem p00202 (C++) — buggy submission, verdict: Time Limit Exceeded

// AOJ 0202
#include <algorithm>
#include <cstring>
#include <iostream>

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

Error: TLE

Fixed submission:

// AOJ 0202
#include <cstring>
#include <iostream>

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;
}
Problem p00202 (C++) — buggy submission, verdict: Runtime Error

#include "bits/stdc++.h"

using namespace std;

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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back

bool isp(int n) {
  if (n == 2)
    return true;
  if (n == 1)
    return false;
  if (n == 0)
    return false;

  for (int i = 2; i <= sqrt(n); i++) {
    if (n % i == 0)
      return false;
  }
  return true;
}

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

    int data[40];
    rep(i, n) { cin >> data[i]; }

    bool dp[1000001] = {};
    rep(i, 1000001) dp[i] = false;

    dp[0] = true;

    for (int i = 1; i <= n; i++) {
      for (int j = 0; j <= x; j++) {
        //                dp[i][j] = dp[i-1][j];
        if (j - data[i - 1] >= 0)
          dp[j] |= dp[j - data[i - 1]];
      }
    }
    int ans = -1;
    for (int i = x; i >= 0; i--) {
      if (dp[i] == true) {
        if (isp(i)) {
          ans = i;
          break;
        }
      }
    }
    if (ans == -1)
      cout << "NA" << endl;
    else
      cout << ans << endl;
  }
}

Error: 0

Fixed submission:

#include "bits/stdc++.h"

using namespace std;

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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back

bool isp(int n) {
  if (n == 2)
    return true;
  if (n == 1)
    return false;
  if (n == 0)
    return false;

  for (int i = 2; i <= sqrt(n); i++) {
    if (n % i == 0)
      return false;
  }
  return true;
}

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

    int data[40];
    rep(i, n) { cin >> data[i]; }

    bool dp[1000001] = {};
    rep(i, 1000001) dp[i] = false;

    dp[0] = true;

    for (int i = 1; i <= n; i++) {
      for (int j = 0; j <= x; j++) {
        //                dp[i][j] = dp[i-1][j];

        dp[j] |= dp[j - data[i - 1]];
      }
    }
    int ans = -1;
    for (int i = x; i >= 0; i--) {
      if (dp[i] == true) {
        if (isp(i)) {
          ans = i;
          break;
        }
      }
    }
    if (ans == -1)
      cout << "NA" << endl;
    else
      cout << ans << endl;
  }
}
Problem p00202 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <string.h>
#include <vector>

using namespace std;
vector<int> prime;
bool isPrime[1000001];
bool dp[1000001];
vector<int> price;

void PrimeCalc() {
  memset(isPrime, 1, sizeof(isPrime));
  isPrime[0] = isPrime[1] = false;
  for (int i = 2; i < 1000001; ++i) {
    if (isPrime[i]) {
      for (int j = 2 * i; j < 1000001; j += i) {
        isPrime[j] = false;
      }
    }
  }
}

void solve() {
  PrimeCalc();
  int n, x;
  while (cin >> n >> x, n || x) {
    price.clear();
    price.resize(n);
    for (int i = 0; i < n; ++i) {
      cin >> price[i];
    }
    memset(dp, 0, sizeof(dp));
    for (int i = 0; i < n; ++i) {
      dp[price[i]] = true;
    }
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j <= x; ++j) {
        if (dp[j] && j + price[i] <= x) {
          dp[j + price[i]] = true;
        }
      }
    }
    bool ok_flag = false;
    for (int i = x; i >= 1; --i) {
      if (dp[i] == true && isPrime[i] == true) {
        cout << i << endl;
        ok_flag = true;
        break;
      }
    }
    if (!ok_flag) {
      cout << "NA" << endl;
    }
  }
}

int main() {
  solve();
  return (0);
}

Error: 0

Fixed submission:

#include <iostream>
#include <string.h>
#include <vector>

using namespace std;
vector<int> prime;
bool isPrime[1000001];
bool dp[1000001];
vector<int> price;

void PrimeCalc() {
  memset(isPrime, 1, sizeof(isPrime));
  isPrime[0] = isPrime[1] = false;
  for (int i = 2; i < 1000001; ++i) {
    if (isPrime[i]) {
      for (int j = 2 * i; j < 1000001; j += i) {
        isPrime[j] = false;
      }
    }
  }
}

void dpCalc(int sum, int &x) {
  if (dp[sum] || sum > x) {
    return;
  } else {
    dp[sum] = true;
  }
  for (int i = 0; i < price.size(); ++i) {
    dpCalc(sum + price[i], x);
  }
}

void solve() {
  PrimeCalc();
  int n, x;
  while (cin >> n >> x, n || x) {
    price.clear();
    price.resize(n);
    for (int i = 0; i < n; ++i) {
      cin >> price[i];
    }
    memset(dp, 0, sizeof(dp));
    dpCalc(0, x);
    bool ok_flag = false;
    for (int i = x; i >= 1; --i) {
      if (dp[i] == true && isPrime[i] == true) {
        cout << i << endl;
        ok_flag = true;
        break;
      }
    }
    if (!ok_flag) {
      cout << "NA" << endl;
    }
  }
}

int main() {
  solve();
  return (0);
}
Problem p00202 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
#include <string.h>
int prime(int);
int p[1000001] = {};
int main() {
  int n, x, v[30], i, j, o, a;
  while (1) {
    memset(p, 0, sizeof(p));
    memset(v, 0, sizeof(v));
    scanf("%d %d", &n, &x);
    if (n == 0 && x == 0) {
      break;
    }
    for (i = 0; i < n; i++) {
      scanf("%d", &v[i]);
      p[v[i]] = 1;
    }
    for (i = 0; i <= x; i++) {
      if (p[i]) {
        for (j = 0; j < n; j++) {
          if (i + v[j] <= x) {
            p[i + v[j]] = 1;
          }
        }
      }
    }
    o = 0;
    for (i = x; i >= 0; i--) {
      if (p[i]) {
        if (prime(i)) {
          o = 1;
          break;
        }
      }
    }
    if (o) {
      printf("%d\\n", i);
    } else {
      printf("NA\\n");
    }
  }
  return 0;
}
int prime(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;
}

Error: 0

Fixed submission:

#include <stdio.h>
long p, cnt, cnt2, food;
int n, d = 0, g, 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++) {
          youso[cnt + kakaku[cnt2]] = 1;
          if (cnt + kakaku[cnt2] > p) {
            break;
          }
        }
      }
    }
    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;
}
Problem p00202 (C++) — buggy submission, verdict: Runtime Error

#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[1000001] = {0};
int main() {
  scanf("%d %d", &n, &p);
  while (1) {
    memset(kakaku, 0, sizeof(kakaku));
    memset(youso, 0, sizeof(youso));
    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;
    for (cnt = 0; cnt <= p; cnt++) {
      youso[cnt] = 0;
    }
    scanf("%d %d", &n, &p);
  }
  return 0;
}

Error: TLE

Fixed submission:

#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 p, cnt, cnt2, food;
int n, d = 0, g, kakaku[31], flag, youso[1000001] = {0};
int main() {
  scanf("%d %d", &n, &p);
  while (1) {
    if (n == 0 && p == 0) {
      break;
    }
    for (cnt = 0; 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;
    for (cnt = 0; cnt <= p; cnt++) {
      youso[cnt] = 0;
    }
    scanf("%d %d", &n, &p);
  }
  return 0;
}
Problem p00202 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
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++)

const int N = 1000000;
int dt[40];
bool prime[N];
bool dp[N];

int main(void) {
  int n, x, lm;
  rep(i, N) { prime[i] = true; }
  for (int i = 2; i < N; i++) {
    for (int j = i * 2; j < N; j += i) {
      prime[j] = false;
    }
  }

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

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
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;
    loop(i, 0, n) {
      cin >> dt[i];
      rep(j, lm) {
        if (j + dt[i] > lm)
          continue;
        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 == 1) {
        cout << "NA" << endl;
        break;
      }
      if (dp[i] && prime[i]) {
        cout << i << endl;
        break;
      }
    }
  }
}