alexjercan/bugnet huggingface dataset:
Problem p00056 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int main() {
  bool p[50000];
  p[1] = false;
  for (int i = 2; i < 50000; i++) {
    p[i] = true;
  }
  for (int j = 2; j < 50000; j++) {
    if (p[j]) {
      for (int k = j * 2; k < 50000; k += j) {
        p[k] = false;
      }
    }
  }
  int n;
  while (cin >> n) {
    if (n == 0)
      break;
    int count = 0;
    if (p[n - 2])
      count++;
    for (int l = 3; l <= n / 2; l += 2) {
      if (p[l] && p[n - l])
        count++;
    }
    cout << count << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  bool p[50000];
  p[1] = false;
  for (int i = 2; i < 50000; i++) {
    p[i] = true;
  }
  for (int j = 2; j < 50000; j++) {
    if (p[j]) {
      for (int k = j * 2; k < 50000; k += j) {
        p[k] = false;
      }
    }
  }
  int n;
  while (cin >> n) {
    if (n == 0)
      break;
    int count = 0;
    if (p[n - 2])
      count++;
    for (int l = 3; l <= n / 2; l += 2) {
      if (p[l]) {
        for (int m = l; m <= n; m++) {
          if (p[m] == true && l + m == n)
            count++;
        }
      }
    }
    cout << count << endl;
  }
  return 0;
}
Problem p00056 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;

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;
  bool prime[50000];
  for (int i = 2; i < 50000; i++)
    if (isprime(i))
      prime[i] = true;
    else
      prime[i] = false;
  while (cin >> n && n) {
    int ans = 0;
    for (int i = 2; i * 2 <= n; i++)
      if (prime[i] && prime[n - i])
        ans++;
    cout << ans << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

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;

  while (cin >> n && n) {
    int ans = 0;
    for (int i = 2; i * 2 <= n; i++)
      if (isprime(i) && isprime(n - i))
        ans++;
    cout << ans << endl;
  }

  return 0;
}
Problem p00056 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>
using namespace std;

int ans[50010] = {};
int prime[50010] = {};
vector<int> VC;

void calc() {

  prime[0] = prime[1] = 1;
  for (int i = 2; i <= 50000; i++) {
    if (!prime[i]) {
      VC.push_back(i);
      for (int j = 2; i * j <= 50000; j++) {
        prime[i * j] = 1;
      }
    }
  }

  for (int i = 4; i <= 50000; i++) {
    for (int j = 0; VC[j] <= i / 2; j++) {
      if (!prime[i - VC[j]])
        ans[i]++;
    }
  }
}

int main() {

  calc();

  int n;
  while (cin >> n, n) {
    cout << ans[n] << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int ans[50010] = {};
int prime[50010] = {};

void calc() {
  prime[0] = prime[1] = 1;
  for (int i = 2; i * i <= 50000; i++) {
    if (!prime[i]) {
      for (int j = 2; i * j <= 50000; j++) {
        prime[i * j] = 1;
      }
    }
  }

  for (int i = 4; i <= 50000; i++) {
    for (int j = 2; j <= i / 2; j++) {
      if (!prime[j] && !prime[i - j])
        ans[i]++;
    }
  }
}

int main() {

  calc();

  int n;
  while (cin >> n, n) {
    cout << ans[n] << endl;
  }

  return 0;
}
Problem p00056 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <functional> //greaterの使用
#include <iostream>
using namespace std;
#define MAX_LIST 60000

bool find_list(int *list, int a, int b, int x) {
  // cout<<list[a]<<" "<<list[b]<<" "<<list[(b+a)/2]<<" "<<x<<endl;
  if (b - a < 2) {
    if (list[b] == x) {
      // cout<<"find"<<endl;
      return true;
    }
    if (find(list + a, list + b, x) != list + b) {
      // cout<<"find"<<endl;
      return true;
    }
    // cout<<"false"<<endl;
    return false;
  }
  if (list[(b + a) / 2] > x) {
    return find_list(list, a, (b + a) / 2, x);
  } else if (list[(a + b) / 2] < x) {
    return find_list(list, (a + b) / 2, b, x);
  }
  // cout<<"find "<<list[(b+a)/2]<<" "<<x<<endl;
  return true;
}

int main() {
  bool prime[MAX_LIST];
  for (int i = 0; i < MAX_LIST; i++) {
    prime[i] = 1;
  }
  prime[0] = prime[1] = 0;
  for (int i = 0; i * i < MAX_LIST; i++) {
    if (prime[i] == 1) {
      for (int j = i * 2; j < MAX_LIST; j = j + i) {
        prime[j] = 0;
      }
    }
  }
  int primelist[60000];
  int j = 0;
  for (int i = 0; i < MAX_LIST; i++) {
    if (prime[i] == 1) {
      primelist[j] = i;
      j++;
      if (j > 60000) {
        break;
      }
    }
  }
  int in;
  while (cin >> in, in) {
    int ans = 0;
    int t = 0;
    int r;
    while (in > primelist[t])
      t++;
    if (in % 2 == 1) {
      r = 2;
    } else {
      r = t;
    }
    for (int i = 0; i < r; i++) {
      if (find_list(primelist, i, t, in - primelist[i])) {
        ans++;
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <functional> //greaterの使用
#include <iostream>
using namespace std;
#define MAX_LIST 60000

bool find_list(int *list, int a, int b, int x) {
  // cout<<list[a]<<" "<<list[b]<<" "<<list[(b+a)/2]<<" "<<x<<endl;
  if (b - a < 2) {
    if (list[b] == x) {
      // cout<<"find"<<endl;
      return true;
    }
    if (find(list + a, list + b, x) != list + b) {
      // cout<<"find"<<endl;
      return true;
    }
    // cout<<"false"<<endl;
    return false;
  }
  if (list[(b + a) / 2] > x) {
    return find_list(list, a, (b + a) / 2, x);
  } else if (list[(a + b) / 2] < x) {
    return find_list(list, (a + b) / 2, b, x);
  }
  // cout<<"find "<<list[(b+a)/2]<<" "<<x<<endl;
  return true;
}

int main() {
  bool prime[MAX_LIST];
  for (int i = 0; i < MAX_LIST; i++) {
    prime[i] = 1;
  }
  prime[0] = prime[1] = 0;
  for (int i = 0; i * i < MAX_LIST; i++) {
    if (prime[i] == 1) {
      for (int j = i * 2; j < MAX_LIST; j = j + i) {
        prime[j] = 0;
      }
    }
  }
  int primelist[60000];
  int j = 0;
  for (int i = 0; i < MAX_LIST; i++) {
    if (prime[i] == 1) {
      primelist[j] = i;
      j++;
      if (j > 60000) {
        break;
      }
    }
  }
  int in;
  while (cin >> in, in) {
    int ans = 0;
    int t = 0;
    while (in > primelist[t])
      t++;
    for (int i = 0; i < t; i++) {
      if (find_list(primelist, i, t, in - primelist[i])) {
        ans++;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p00056 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
#define MAX 50100

int prime[MAX - 4];

void is_prime() {
  for (int i = 0; i < MAX; i++)
    prime[i] = 0;
  prime[0] = prime[1] = 1;
  for (int i = 4; i < MAX; i += 2)
    prime[i] = 1;

  for (int i = 3; i * i < MAX; i++) {
    if (prime[i])
      continue;
    for (int j = i * 2; j < MAX; j += i)
      prime[j] = 1;
  }
}

int main() {
  int n;

  is_prime();

  while (true) {
    cin >> n;
    if (!n)
      break;

    int cnt = 0;
    for (int i = 2; i <= n / 2; i++) {
      if (!prime[i] && !prime[n - i])
        cnt++;
    }
    cout << cnt << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
#define MAX 50100

int P[MAX + 1];

void is_prime() {
  for (int i = 0; i <= MAX; i++)
    P[i] = 0;
  for (int i = 4; i <= MAX; i += 2)
    P[i] = 1;

  for (int i = 3; i * i <= MAX; i++) {
    if (P[i])
      continue;
    for (int j = i * 2; j * j <= MAX; j += i)
      P[j] = 1;
  }
}

int main() {
  int n;

  is_prime();
  for (;;) {
    cin >> n;
    if (!n)
      break;

    int cnt = 0;
    for (int i = n; i * i > 0; i--) {
      for (int j = n - 1; j > 0; j--) {
        if (!P[i] && !P[j] && i + j == n && i >= j)
          cnt++;
      }
    }
    cout << cnt << endl;
  }

  return 0;
}
Problem p00056 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int main() {
  int n;
  bool f[50010];
  memset(f, true, sizeof(f));
  f[1] = false;
  f[0] = false;
  for (int i = 2; i < 300; i++) {
    if (f[i]) {
      for (int j = i * i; j < 50001; j += i)
        f[j] = false;
    }
  }
  while (cin >> n, n) {
    int ans = 0;
    for (int i = 2; i <= n / 2; i++) {
      if (f[i] && f[n - i])
        ans++;
    }
    cout << ans << endl;
  }
}

Error: 0

Fixed submission:

#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int main() {
  int n;
  bool f[25001];
  memset(f, true, sizeof(f));
  f[1] = false;
  f[0] = false;
  for (int i = 2; i < 25001; i++) {
    if (f[i]) {
      for (int j = i * i; j < 25001; j += i)
        f[j] = false;
    }
  }
  while (cin >> n, n) {
    int ans = 0;
    for (int i = 2; i <= n / 2; i++) {
      if (f[i] && f[n - i])
        ans++;
    }
    cout << ans << endl;
  }
}
Problem p00056 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
using namespace std;

bool prime[50010];
int ans[50010];

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

  for (int i = 2; i <= 25000; ++i) {
    if (prime[i]) {
      for (int j = i; j + i <= 50000; ++j) {
        if (prime[j]) {
          ++ans[i + j];
        }
      }
    }
  }

  int n;
  while (scanf("%d", &n), n) {
    printf("%d\\n", ans[n]);
  }
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <ctime>
using namespace std;

int main() {
  int c = 0, x;
  while (scanf("%d", &x), x)
    ++c;

  clock_t z = clock() + c * CLOCKS_PER_SEC * 0.01;
  while (z > clock())
    ;
}
Problem p00056 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#define MAX 50000

using namespace std;

bool is_prime[MAX];

void tenes(void) {

  for (int i = 0; i < MAX; i++) {
    is_prime[i] = true;
  }
  is_prime[0] = is_prime[1] = false;

  for (int i = 2; i * i < MAX; i++) {
    if (is_prime[i]) {
      for (int j = i + i; j < MAX; j += i) {
        is_prime[j] = false;
      }
    }
  }
}

int main(void) {

  tenes();

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

    int cnt = 0;
    for (int i = 2; i <= n / 2; i++) {
      if (is_prime[i] && is_prime[n - i]) {
        cnt++;
      }
    }
    cout << cnt << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#define MAX 50000

using namespace std;

bool is_prime[MAX];

void tenes(void) {

  for (int i = 0; i < MAX; i++) {
    is_prime[i] = true;
  }
  is_prime[0] = is_prime[1] = false;

  for (int i = 2; i * i < MAX; i++) {
    if (is_prime[i]) {
      for (int j = i + i; j < MAX; j += i) {
        is_prime[j] = false;
      }
    }
  }
}

int main(void) {

  tenes();

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

    int cnt = 0;
    int N;
    for (int i = 2; i < MAX / 2; i++) {
      if (is_prime[i]) {
        if (n - i > 0) {
          N = n - i;
          if (is_prime[N] && N >= n / 2) {
            cout << N << endl;
            cnt++;
          }
        }
      }
    }
    cout << cnt << endl;
  }
  return 0;
}
Problem p00056 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <math.h>
using namespace std;

int main() {
  bool is_prime[50001];
  is_prime[0] = false;
  is_prime[1] = false;
  for (int i = 2; i < 50001; i++)
    is_prime[i] = true;
  for (int i = 2; i <= sqrt(50001); i++) {
    if (is_prime[i]) {
      for (int j = 2; i * j <= 50001; j++)
        is_prime[i * j] = false;
    }
  }

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

    for (int i = 2; i <= n / 2; i++) {
      if (is_prime[i]) {
        if (is_prime[n - i])
          cnt++;
      }
    }
    cout << cnt << endl;
  }
}


Error: TLE

Fixed submission:

#include <iostream>
#include <math.h>
using namespace std;

int main() {
  bool is_prime[50001];
  is_prime[0] = false;
  is_prime[1] = false;
  for (int i = 2; i < 50001; i++)
    is_prime[i] = true;
  for (int i = 2; i <= sqrt(50001); i++) {
    if (is_prime[i]) {
      for (int j = 2; i * j <= 50001; j++)
        is_prime[i * j] = false;
    }
  }

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

    for (int i = 2; i < n; i++) {
      if (!is_prime[i])
        continue;
      for (int j = 2; j < n; j++) {
        if (!is_prime[j])
          continue;
        if (i + j == n) {
          if (i == j)
            cnt += 2;
          else
            cnt++;
        }
      }
    }
    cout << cnt / 2 << endl;
  }
}
Problem p00056 (C++) — buggy submission, verdict: Time Limit Exceeded

// Goldbach's Conjecture
#include <bits/stdc++.h>
using namespace std;

vector<int> p;
int ans[50001];

void solve() {
  int ret = 0;
  for (int i = 0; i < p.size(); i++)
    for (int j = i; j < p.size(); j++) {
      if (p[i] + p[j] > 50000)
        break;
      ans[p[i] + p[j]]++;
    }
}

int main() {
  p.push_back(2);
  for (int i = 3; i < 50000; i += 2) {
    bool flag = true;
    for (int j = 0; j < p.size(); j++)
      if (i % p[j] == 0) {
        flag = false;
        break;
      }
    if (flag) {
      p.push_back(i);
    }
  }
  solve();

  int n;
  while (true) {
    cin >> n;
    if (n == 0)
      break;
    cout << ans[n] << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

// Goldbach's Conjecture
#include <bits/stdc++.h>
using namespace std;

vector<int> p;
int ans[50001];

void solve() {
  int ret = 0;
  for (int i = 0; i < p.size(); i++)
    for (int j = i; j < p.size(); j++) {
      if (p[i] + p[j] > 50000)
        break;
      ans[p[i] + p[j]]++;
    }
}

int main() {
  p.push_back(2);
  for (int i = 3; i < 50000; i += 2) {
    bool flag = true;
    for (int j = 0; j < p.size(); j++)
      if (i % p[j] == 0) {
        flag = false;
        break;
      }
    if (flag) {
      p.push_back(i);
    }
  }
  solve();

  int n;
  while (true) {
    cin >> n;
    cout << ans[n] << endl;
  }
  return 0;
}
Problem p00056 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>

using namespace std;

int main() {
  int n, c, p = 1;
  bool f, a[50001];

  fill(a, a + 50001, false);
  for (int i = 3; i < 50000; i += 2) {
    f = true;
    a[2] = true;
    for (int j = 3; j * j <= i; j += 2) {
      if (i % j == 0) {
        f = false;
        break;
      }
    }
    a[i] = f;
  }

  while (1) {
    cin >> n;
    if (n == 0) {
      break;
    }
    c = 0;
    for (int i = 2; i <= n / 2; i++) {
      if (a[i] && a[n - i]) {
        c++;
      }
    }
    cout << c << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int prime(int n) {
  if (n < 2) {
    return 0;
  } else if (n == 2) {
    return 1;
  }

  if (n % 2 == 0) {
    return 0;
  }

  for (int i = 3; i * i <= n; i += 2) {
    if (n % i == 0) {
      return 0;
    }
  }

  return 1;
}

int main(int argc, char **argv) {
  int n, c;

  while (1) {
    cin >> n;
    if (n == 0) {
      break;
    }
    c = 0;
    if (n % 2 != 0) {
      cout << c << endl;
      continue;
    }

    for (int i = 3, tmp = n; i < tmp; i += 2) {
      if (prime(i) == 1 && prime(n - i) == 1) {
        c++;
        tmp = n - i;
      }
    }

    cout << c << endl;
  }

  return 0;
}
Problem p00056 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define FOR(i, a, b) for (long long i = (a); i < (b); i++)
#define REP(i, N) for (long long i = 0; i < (N); i++)
#define ALL(s) (s).begin(), (s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;

int n;
int prime[50001];
V v;
ll ans[50001];

int main() {
  fill(prime, prime + 50000, 1);
  prime[0] = prime[1] = 0;
  for (int i = 2; i * i <= 50000; i++) {
    if (prime[i] == 1) {
      for (int j = 2 * i; j <= 50000; j += i) {
        prime[j] = 0;
      }
    }
  }
  for (int i = 0; i < 50000; i++) {
    if (prime[i] == 1)
      v.push_back(i);
  }
  REP(i, v.size()) {
    FOR(j, i, v.size()) {
      if (v[i] + v[j] > 50000)
        continue;
      ans[v[i] + v[j]]++;
    }
  }
  while (cin >> n && n) {
    cout << ans[n] << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define FOR(i, a, b) for (long long i = (a); i < (b); i++)
#define REP(i, N) for (long long i = 0; i < (N); i++)
#define ALL(s) (s).begin(), (s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;

int n;
int prime[50000];
V v;

int main() {
  fill(prime, prime + 50000, 1);
  prime[0] = prime[1] = 0;
  for (int i = 2; i < 50000; i++) {
    if (prime[i] == 1) {
      for (int j = 2 * i; j < 50000; j += i) {
        prime[j] = 0;
      }
    }
  }
  for (int i = 0; i < 50000; i++) {
    if (prime[i] == 1)
      v.push_back(i);
  }
  while (cin >> n && n) {
    ll ans = 0;
    REP(i, v.size()) {
      FOR(j, i, v.size()) {
        if (v[i] + v[j] == n) {
          ans++;
          // cout << v[i] << " " << v[j] << endl;
        }
      }
    }
    cout << ans << endl;
  }
}
Problem p00056 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int search(const int array[], int high, int key) {
  int low = 0;
  int mid;
  int n = -1;
  while (low <= high) {
    mid = (low + high) / 2;
    if (array[mid] == key) {
      n = mid;
      break;
    } else if (array[mid] < key) {
      low = mid + 1;
    } else {
      high = mid - 1;
    }
  }
  return (n);
}

int main(void) {
  int prime[5136];
  prime[1] = 2;
  prime[2] = 3;
  int ptr = 3;
  for (int num = 5; num <= 50000; num++) {
    bool f = false;
    for (int i = 1; i < ptr; i++) {
      if (prime[i] * prime[i] > num) {
        break;
      }
      if (num % prime[i] == 0) {
        f = true;
        break;
      }
    }
    if (!f) {
      prime[ptr++] = num;
    }
  }
  prime[ptr] = 50001;
  int n;
  while (cin >> n) {
    if (!n)
      break;
    int count = 0;
    if (n % 2 == 0) {
      for (int i = 1; prime[i] <= n / 2; i++) {
        if (search(prime, ptr, n - prime[i]) != -1)
          count++;
      }
    } else {
      if (search(prime, ptr, n - 2) != -1)
        count++;
    }
    cout << count << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main(void) {
  int prime[5136];
  prime[1] = 2;
  prime[2] = 3;
  int ptr = 3;
  for (int num = 5; num <= 50000; num++) {
    bool f = false;
    for (int i = 1; i < ptr; i++) {
      if (prime[i] * prime[i] > num) {
        break;
      }
      if (num % prime[i] == 0) {
        f = true;
        break;
      }
    }
    if (!f) {
      prime[ptr++] = num;
    }
  }
  prime[ptr] = 50001;
  int n;
  while (cin >> n) {
    if (!n)
      break;
    int count = 0;
    for (int i = 0; prime[i] < n; i++) {
      for (int j = i; prime[j] < n; j++) {
        if (n == prime[i] + prime[j])
          count++;
      }
    }
    cout << count << endl;
  }
  return 0;
}
Problem p00056 (C++) — buggy submission, verdict: Time Limit Exceeded

#include "bits/stdc++.h"

using namespace std;

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

#define dump(x) cerr << #x << " = " << (x) << endl
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back

bool era[10000000] = {false};

void makeERA() {
  for (int i = 2; i < 1000001; i++) {
    if (era[i] != true)
      continue;
    for (int j = 2;; j++) {
      if (i * j <= 1000000)
        era[i * j] = false;
      else
        break;
    }
  }
  era[2] = true;
}
int main() {
  rep(i, 10000000) era[i] = true;
  era[0] = false;
  era[1] = false;
  makeERA();
  int n;
  while (cin >> n) {
    if (n == 0)
      break;

    int sum = 0;
    for (int i = 2; i <= (int)n / 2; i++) {
      if (era[i]) {
        if (era[n - i]) {
          sum++;
        }
      }
    }
    cout << sum << endl;
  }
}

Error: TLE

Fixed submission:

#include "bits/stdc++.h"

using namespace std;

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

#define dump(x) cerr << #x << " = " << (x) << endl
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back

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

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

    int sum = 0;
    for (int i = 2; i <= (int)n / 2; i++) {
      if (isp(i)) {
        if (isp(n - i)) {
          sum++;
        }
      }
    }
    cout << sum << endl;
  }
}
Problem p00056 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <math.h>
using namespace std;
int p[50000] = {0};

int main() {
  int n, q, count, k, l = 0;

  for (int i = 2; i <= 300; i++)
    for (int j = i * 2; j <= 50000; j += i) {
      p[j] = 1;
    }

  while ((cin >> n), n) {
    int count = 0;
    for (int i = 2; i <= n / 2; i++) {
      if (p[n - i] == 0 && p[i] == 0)
        count++;
    }
    cout << count << endl;
  }
  return 0;
}

Error: -11

Fixed submission:

#include <iostream>
#include <math.h>
using namespace std;
int p[20000];
int main() {
  int n, q, j, count, k, l = 0;
  p[0] = 2;
  for (int i = 3; i <= 50000; i++) {
    k = (int)sqrt(i);
    for (j = 2; j <= k + 1; j++) {
      if (i % j == 0)
        break;
    }
    if (j == k + 1)
      p[++l] == i;
  }

  while ((cin >> n), n) {
    count = 0;
    for (int i = 0; p[i] <= n / 2; i++) {
      q = n - p[i];
      if (q <= 1)
        continue;
      for (int j = 2; j <= (int)sqrt(q) + 1; j++) {
        if (j == (int)sqrt(q) + 1)
          count++;
        else if (q % j == 0)
          break;
      }
    }
    cout << count << endl;
  }
  return 0;
}