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

#include <iostream>
using namespace std;

int p[50001] = {0};

int main() {
  for (int i = 4; i <= 50000; i++) {
    if (i % 2 == 0)
      p[i] = 1;
    for (int j = 3; j * j <= i; j++) {
      if (i % j == 0) {
        p[i] = 1;
      }
    }
  }

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

    cout << cnt << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

bool isPrime(int a) {
  for (int i = 3; i * i <= a; i += 2) {
    if (a % i == 0)
      return false;
  }
  return true;
}

int main() {
  int n;
  while (cin >> n && n) {
    if (n % 2) {
      if (isPrime(n - 2)) {
        cout << 1 << endl;
      } else {
        cout << 0 << endl;
      }
      continue;
    }
    int cnt = 0;
    for (int i = 3; i <= n / 2; i += 2) {
      if (isPrime(i)) {
        if (isPrime(n - i)) {
          cnt++;
        }
      }
    }

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

#include <bits/stdc++.h>
using namespace std;

int main() {
  int N = 50000;
  vector<int> primes;
  vector<bool> is_prime(N, true);

  for (int j = 2; j <= N; j++) {
    if (is_prime[j]) {
      for (int k = 2; k <= N / j; k++) {
        is_prime[j * k] = false;
      }
    }
  }

  while (1) {
    int n;
    cin >> n;
    int m = n / 2;
    if (n == 0)
      break;
    int res = 0;
    for (int j = 2; j <= m; j++) {
      if (is_prime[j] && is_prime[n - j]) {
        res++;
      }
    }
    cout << res << endl;
  }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

int main() {
  int N = 50000;
  vector<int> primes;

  for (int j = 2; j <= N; j++) {
    bool is_prime = true;
    for (int prime : primes) {
      is_prime = is_prime && (j % prime != 0);
    }
    if (!is_prime)
      continue;
    primes.push_back(j);
  }

  while (1) {
    int n;
    cin >> n;
    if (n == 0)
      break;
    int res = 0;
    if (n % 2 == 0) {
      for (int j = 1; j < primes.size(); j++) {
        for (int k = j; k < primes.size(); k++) {
          if (primes[j] + primes[k] == n)
            res++;
        }
      }
    } else {
      for (int j = 1; j < primes.size(); j++) {
        if (primes[j] == n - 2)
          res++;
      }
    }
    cout << res << endl;
  }
}
Problem p00056 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  bool is_prime[50001];

  is_prime[0] = is_prime[1] = false;

  for (int i = 2; i < 50001; i++) {
    is_prime[i] = true;
  }

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

  while (true) {
    int n;
    cin >> n;

    if (n == 0)
      break;

    int match = 0;

    for (int i = 2; i <= n / 2; i++) {
      if (is_prime[i] && is_prime[n - i])
        match++;
    }

    cout << match << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  bool is_prime[50001];

  is_prime[0] = is_prime[1] = false;

  for (int i = 2; i < 50001; i++) {
    is_prime[i] = true;
  }

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

  int n_prime[50001];
  int prime[50001];

  int cnt = 0;
  for (int i = 2; i < 50001; i++) {
    if (is_prime[i]) {
      prime[cnt] = i;
      cnt++;
    }

    n_prime[i] = cnt;
  }

  int match;
  int N;

  while (true) {
    int n;
    cin >> n;

    N = n_prime[n];

    if (n == 0)
      break;

    match = 0;

    for (int i = 0; i <= N / 2; i++) {
      for (int j = N - 1; j >= (N - 1) / 2; j--) {
        if (prime[i] + prime[j] == n)
          match++;
      }
    }

    cout << match << endl;
    n++;
  }

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

#include <algorithm>
#include <iostream>
#include <string.h>
#define MAX 50000
using namespace std;

int dp[MAX + 1];
int prm[MAX + 1];

int main() {
  for (int i = 2; i <= MAX; i++)
    prm[i] = 1;
  for (int i = 2; i <= MAX; i++)
    for (int j = 2; j * i <= MAX; j++)
      prm[i * j] = 0;
  int n;
  for (int i = 0; i <= MAX; i++)
    for (int j = i; j + i <= MAX; j++)
      if (prm[i] == 1 && prm[j] == 1)
        dp[i + j]++;
  while (cin >> n, n > 0) {
    cout << dp[n] << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string.h>
#define MAX 50000
using namespace std;

int dp[MAX];
int prm[MAX];

int main() {
  fill(prm, prm + MAX, 1);
  prm[0] = prm[1] = 0;
  for (int i = 2; i < MAX; i++)
    for (int j = 2; j * i <= MAX; j++)
      prm[i * j] = 0;

  int n;
  while (cin >> n, n > 0) {
    if (prm[n]) {
      cout << "0" << endl;
      continue;
    }
    if (dp[n] > 0) {
      cout << dp[n] << endl;
      continue;
    }
    for (int i = 0; i < n; i++)
      for (int j = i; j < n; j++)
        if (prm[i] == 1 && prm[j] == 1 && i + j == n)
          dp[n]++;
    cout << dp[n] << endl;
  }

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

#include <cmath>
#include <iostream>
using namespace std;
void pp(char *f, long x) {
  long i, p, k;
  for (i = 1; i <= x; i++)
    f[i] = 0;
  f[2] = f[3] = 1;
  for (i = 7; i <= x; i += 6)
    f[i] = 1;
  for (i = 5; i <= x; i += 6)
    f[i] = 1;
  for (i = 0; i <= ceil(sqrt(x) / 6); i++) {
    p = 6 * i + 1;
    if (f[p]) {
      for (k = p * p; k <= x; k += p * 6)
        f[k] = 0;
      for (k = p * (p + 4); k <= x; k += p * 6)
        f[k] = 0;
    }
    p = 6 * i + 5;
    if (f[p]) {
      for (k = p * p; k <= x; k += p * 6)
        f[k] = 0;
      for (k = p * (p + 2); k <= x; k += p * 6)
        f[k] = 0;
    }
  }
}
int main() {
  long i, n, s;
  char *f;
  f = new char[50001];
  pp(f, 50000);
  while (cin >> n, n) {
    s = 0;
    if (n == 4) {
      s++;
    } else if (n / 2 * 2 == n) {
      for (i = 3; i * 2 <= n; i += 2)
        if (f[i] && f[n - i])
          s++;
    } else {
      if (f[n - 2])
        s++;
    }
    cout << s << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
bool isPrime(long n) {
  long i;
  for (i = 3; i * i <= n; i += 2) {
    if (n / i * i == n)
      return false;
  }
  return true;
}
int main() {
  long i, n, s;
  while (cin >> n, n) {
    s = 0;
    if (n / 2 * 2 == n) {
      for (i = 3; i * 2 <= n; i += 2)
        if (isPrime(i) && isPrime(n - i))
          s++;
    } else {
      if (isPrime(n - 2))
        s++;
    }
    cout << s << endl;
  }
  return 0;
}
Problem p00056 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

int n;
int p;
bool isprime[50001];
int prime[50001];
int flg[25000001];

void sieve(int x) {
  p = 0;

  isprime[0] = isprime[1] = false;
  for (int i = 2; i <= x; i++)
    isprime[i] = true;

  for (int i = 2; i <= x; i++) {
    if (isprime[i]) {
      prime[p++] = i;

      for (int j = i * 2; j <= x; j += i)
        isprime[j] = false;
    }
  }
}

int main() {
  sieve(50000);

  for (int i = 0; i < p; i++) {
    for (int j = i; j < p; j++) {
      flg[prime[i] + prime[j]]++;
    }
  }

  while (1) {
    std::cin >> n;
    if (!n)
      break;

    std::cout << flg[n] << std::endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

int n;
int p;
bool isprime[50001];
int prime[50001];

void sieve(int x) {
  p = 0;

  isprime[0] = isprime[1] = false;
  for (int i = 2; i <= x; i++)
    isprime[i] = true;

  for (int i = 2; i <= x; i++) {
    if (isprime[i]) {
      prime[p++] = i;

      for (int j = i * 2; j <= x; j += i)
        isprime[j] = false;
    }
  }
}

int main() {
  sieve(50000);

  while (1) {
    std::cin >> n;
    if (!n)
      break;

    int ans = 0;

    for (int i = 0; i < p; i++) {
      for (int j = i; j < p; j++) {
        if (prime[i] + prime[j] == n)
          ans++;
      }
    }

    std::cout << ans << std::endl;
  }

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

#include <algorithm>
#include <iostream>
#include <list>
#include <map>
#include <stdio.h>
#include <string.h>
#include <vector>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) range(i, 0, b)
#define debug(x) cout << x << endl;
using namespace std;

int main() {
  bool prime[200000];
  int primeNum[10100] = {0};
  rep(i, 105000) { prime[i] = true; }
  prime[0] = false;
  prime[1] = false;
  int j = 1;
  rep(i, 105000) {
    if (prime[i]) {
      primeNum[j] = i;
      j++;
      for (int k = 2 * i; k < 105000; k += i) {
        prime[k] = false;
      }
    }
  }
  int ans[50001];
  range(i, 1, 50000) {
    if (primeNum[i] > 50000)
      break;
    range(j, i, 50000) {
      if (primeNum[i] + primeNum[j] > 50000)
        break;
      ans[primeNum[i] + primeNum[j]]++;
    }
  }
  int input;
  while (cin >> input, input) {
    cout << ans[input] << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <list>
#include <map>
#include <stdio.h>
#include <string.h>
#include <vector>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) range(i, 0, b)
#define debug(x) cout << x << endl;
using namespace std;

int main() {
  bool prime[200000];
  int primeNum[10100] = {0};
  rep(i, 105000) { prime[i] = true; }
  prime[0] = false;
  prime[1] = false;
  int j = 1;
  rep(i, 105000) {
    if (prime[i]) {
      primeNum[j] = i;
      j++;
      for (int k = 2 * i; k < 105000; k += i) {
        prime[k] = false;
      }
    }
  }
  int input;
  while (cin >> input, input) {
    int ans = 0;
    range(i, 1, 105000) {
      if (input < primeNum[i])
        break;
      range(k, i, 105000) {
        if (input == primeNum[i] + primeNum[k])
          ans++;
        if (input < primeNum[i] + primeNum[k])
          break;
      }
    }
    cout << ans << endl;
  }
}
Problem p00056 (C++) — buggy submission, verdict: Time Limit Exceeded

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

Error: TLE

Fixed submission:

#include <iostream>
#include <string>
using namespace std;
int main() {
  int n, count = 0;
  int b[6000];
  int i = 3;
  while (true) {
    bool t = false;
    for (int j = 2; j * j < i + 1; j++) {
      if (i % j == 0)
        t = true;
    }
    if (t == false) {
      b[count] = i;
      count++;
    }
    if (count == 5999)
      break;
    i++;
  }
  while (true) {
    count = 0;
    cin >> n;
    if (n == 0)
      break;
    int h = 0;
    while (true) {
      if (b[h] > n)
        break;
      h++;
    }
    if (n % 2 == 1) {
      int i = h;
      while (true) {
        if (b[i] < n - 2)
          break;
        if (b[i] == n - 2)
          count = 1;
        i--;
      }
    } else {
      int i = 0;
      while (true) {
        if (b[i] > n / 2) {
          break;
        }
        int j = h;
        while (true) {
          if (b[j] < n - b[i])
            break;
          if (b[i] + b[j] == n)
            count++;
          j--;
        }
        i++;
      }
    }
    cout << count << endl;
  }
  return 0;
}
Problem p00056 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <vector>

#define X first
#define Y second
using namespace std;

void era(bool *table) {
  for (int i = 2; i <= 50000; i++) {
    if (table[i]) {
      for (int j = i * 2; j <= 50000; j += i) {
        table[j] = false;
      }
    }
  }
}

int main() {
  bool table[50001];
  memset(table, true, sizeof(table));
  table[0] = false;
  table[1] = false;
  era(table);
  int n;
  while (cin >> n && n != 0) {
    int count = 0;
    for (int i = 2; i <= n; i++) {
      if (!table[i])
        continue;
      if (table[n - i])
        count++;
      if (i == n - i)
        count++;
    }
    cout << count / 2 << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <vector>

#define X first
#define Y second
using namespace std;

void era(bool *table) {
  for (int i = 2; i <= 50000; i++) {
    if (table[i]) {
      for (int j = i * 2; j <= 50000; j += i) {
        table[j] = false;
      }
    }
  }
}

int combi(int target, bool *table) {
  int count = 0;
  if (target % 2)
    return 0;
  for (int i = 1; i <= target / 2; i++) {
    for (int j = i; j <= target; j++) {
      if (!table[i] || !table[j])
        continue;
      if (i + j == target)
        count++;
      if (i + j > target)
        break;
    }
  }
  return count;
}

int main() {
  bool table[50001];
  memset(table, true, sizeof(table));
  era(table);
  vector<int> res;
  for (int i = 0; i <= 50000; i++) {
    res.push_back(combi(i, table));
  }
  int n;
  while (cin >> n && n != 0) {
    cout << res[n] << endl;
  }
  return 0;
}
Problem p00056 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i, n) for (i = 0; i < n; i++)
#define loop(i, a, n) for (i = a; i < n; i++)
#define all(in) in.begin(), in.end()
#define shosu(x) fixed << setprecision(x)

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

int main(void) {
  int i, j;
  int n;
  vector<bool> prime(60000, true);

  for (i = 2; i < 60000; i++)
    if (prime[i])
      for (j = 2; i * j < 60000; j++)
        prime[i * j] = false;

  vi ans(60000, 0);

  for (i = 2; i < 60000; i++)
    if (prime[i])
      for (j = i; j < 60000; j++)
        if (prime[j] && i + j < 60000)
          ans[i + j]++;

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

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i, n) for (i = 0; i < n; i++)
#define loop(i, a, n) for (i = a; i < n; i++)
#define all(in) in.begin(), in.end()
#define shosu(x) fixed << setprecision(x)

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

int main(void) {
  int i, j;
  int n;
  vector<bool> prime(40000, true);

  for (i = 2; i < 40000; i++)
    if (prime[i])
      for (j = 2; i * j < 40000; j++)
        prime[i * j] = false;

  vi ans(40000, 0);

  for (i = 2; i < 40000; i++)
    if (prime[i])
      for (j = i; j < 40000; j++)
        if (prime[j] && i + j < 40000)
          ans[i + j]++;

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

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

int main() {
  bool primes[50000] = {false};
  primes[0] = true;
  for (int i = 2; i <= 25000; ++i) {
    if (primes[i - 1])
      continue;
    for (int j = i + i; j <= 50000; j += i) {
      primes[j - 1] = true;
    }
  }

  int n;
  while (cin >> n && n) {
    int cnt = 0;
    for (int i = 2; i <= n / 2; ++i) {
      if (!primes[i - 1] && !primes[n - i - 1]) {
        ++cnt;
      }
    }
    printf("%d\\n", cnt);
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <cmath>
#include <cstdio>
#include <ctime>
#include <iostream>
#include <vector>
using namespace std;

bool isprime(int n) {
  for (int i = 2, len = sqrt(n); i <= len; ++i)
    if (!(n % i))
      return false;
  return true;
}

int main() {
  bool primes[50000] = {false};
  primes[0] = true;
  for (int i = 2; i <= 25000; ++i) {
    if (primes[i - 1])
      continue;
    for (int j = i * 2; j <= 50000; j += i) {
      primes[j - 1] = true;
    }
  }

  vector<int> prime;
  for (int i = 0; i < 50000; ++i)
    if (!primes[i])
      prime.push_back(i + 1);

  int n;
  int result[50000] = {0};
  while (cin >> n && n) {
    if (n % 2) {
      printf("%d\\n", 0);
      continue;
    } else if (result[n - 1]) {
      printf("%d\\n", result[n - 1]);
      continue;
    }
    int cnt = 0;
    bool check[50000] = {false};
    for (int i = 0, len = prime.size(); i < len; ++i) {
      if (n - 1 <= prime[i])
        break;
      if (check[n - prime[i] - 1])
        break;
      if (isprime(n - prime[i])) {
        ++cnt;
        check[prime[i] - 1] = true;
      }
    }
    printf("%d\\n", cnt);
    result[n - 1] = cnt;
  }

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

#include <iostream>
#include <vector>

using namespace std;
vector<int> prime;
bool isPrime[51000];

void PrimeCalc() {
  isPrime[0] = isPrime[1] = false;
  for (int i = 2; i < 51000; ++i) {
    isPrime[i] = true;
  }
  for (int i = 2; i < 51000; ++i) {
    if (isPrime[i]) {
      prime.push_back(i);
      for (int j = 2 * i; j < 51000; j += i) {
        isPrime[j] = false;
      }
    }
  }
}

void solve() {
  PrimeCalc();
  int n;
  while (cin >> n, n) {
    int count = 0;
    for (int i = 0; i < prime.size(); ++i) {
      if (prime[i] > n / 2) {
        break;
      }
      if (isPrime[n - prime[i]]) {
        ++count;
      }
    }
    cout << count << endl;
  }
}

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

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;
vector<int> prime;
bool isPrime[51000];

void PrimeCalc() {
  isPrime[0] = isPrime[1] = false;
  for (int i = 2; i < 51000; ++i) {
    isPrime[i] = true;
  }
  for (int i = 2; i < 51000; ++i) {
    if (isPrime[i]) {
      prime.push_back(i);
      for (int j = 2 * i; j < 51000; j += i) {
        isPrime[j] = false;
      }
    }
  }
}

void solve() {
  PrimeCalc();
  int n;
  while (cin >> n, n) {
    int count = 0;
    for (int i = 0; i < prime.size(); ++i) {
      if (prime[i] >= n / 2 + 1) {
        break;
      }
      for (int j = i; j < prime.size(); ++j) {
        if (prime[i] + prime[j] > n) {
          break;
        } else if (prime[i] + prime[j] == n) {
          ++count;
          break;
        }
      }
    }
    cout << count << endl;
  }
}

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

#include <iostream>
#include <string>
#include <vector>
#define N 50001
using namespace std;

int main() {
  vector<bool> sosuu(N, true);
  for (int b = 2; b < N; b++) {
    if (sosuu[b]) {
      for (int c = b * 2; c < N; c += b)
        sosuu[c] = false;
    }
  }
  int d;
  while (cin >> d, d) {
    int s = 0;
    for (int e = 2; e <= d / 2; e++) {
      if (sosuu[e] && sosuu[d - e])
        s++;
    }
    cout << s << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
#define int long long
using namespace std;

bool prime(int a, int b) {
  if (a == 3) {
    for (int d = 3;; d += 2) {
      if (b % d == 0)
        return false;
      if ((d + 1) * (d + 1) > b)
        return true;
    }
  }
  int c = 3;
  for (;; c += 2) {
    if (a % c == 0 || b % c == 0)
      return false;
    if ((c + 1) * (c + 1) > a)
      break;
  }
  for (int d = c;; d += 2) {
    if (b % d == 0)
      return false;
    if ((d + 1) * (d + 1) > b)
      return true;
  }
}
signed main() {
  int a;
  while (cin >> a, a) {
    int s = 0;
    if (a == 4 || a == 5) {
      cout << 1 << endl;
      continue;
    }
    if (a % 2 == 0) {
      for (int b = 3; b <= a / 2; b += 2) {
        if (prime(b, a - b)) {
          s++;
        }
      }
    } else {
      if (prime(2, a - 2))
        s++;
    }
    cout << s << endl;
  }
}
Problem p00056 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;

vector<long long int> init() {
  vector<bool> prime(50001, 1);
  vector<long long int> ret;
  prime[0] = 0;
  prime[1] = 0;
  for (size_t i = 2; i <= sqrtl(50001); i++) {
    if (prime[i]) {
      int j = 1;
      while (i * ++j < 50001) {
        prime[i * j] = 0;
      }
    }
  }
  for (size_t i = 0; i < 50001; i++) {
    if (prime[i]) {
      ret.emplace_back(i);
    }
  }
  return ret;
}

int main() {
  auto prime = init();
  vector<long long int> ans(50001);
  for (size_t i = 0; i < prime.size(); i++) {
    for (size_t j = i; j < prime.size(); j++) {
      if (prime[i] + prime[j] < 50001) {
        ans[prime[i] + prime[j]]++;
      }
    }
  }
  long long int N;
  while (cin >> N, N) {
    cout << ans[N] << endl;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

vector<long long int> init() {
  vector<bool> prime(50001, 1);
  vector<long long int> ret;
  prime[0] = 0;
  prime[1] = 0;
  for (size_t i = 2; i < 50001; i++) {
    if (prime[i]) {
      int j = 2;
      while (i * j < 50001) {
        prime[i * j] = 0;
      }
      ret.emplace_back(i);
    }
  }
  return ret;
}

int main() {
  auto prime = init();
  vector<long long int> ans(50001);
  for (size_t i = 0; i < prime.size(); i++) {
    for (size_t j = i; j < prime.size(); j++) {
      if (prime[i] + prime[j] < 50001) {
        ans[prime[i] + prime[j]]++;
      }
    }
  }
  long long int N;
  while (cin >> N, N) {
    cout << ans[N] << endl;
  }
}
Problem p00056 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
#define MAX 50004
#define MAXL 3000
int dp[MAX], d[MAX];

int main() {
  int n, m = 0;
  static bool c[MAX] = {true, true};
  for (int i = 2; i < MAX; i++) {
    if (!c[i]) {
      for (int j = 2; i * j < MAX; j++)
        c[i * j] = true;
      d[m++] = i;
    }
  }

  for (int i = 0; i < MAXL; i++)
    for (int j = i; d[i] + d[j] < MAX - 3; j++)
      dp[d[i] + d[j]]++;
  while (cin >> n, n)
    cout << dp[n] << endl;
  return 0;
}

Error: -11

Fixed submission:

#include <iostream>
using namespace std;
#define MAX 50004
#define MAXL 3000
int dp[MAX], d[MAX];

int main() {
  int n, m = 0;
  static bool c[MAX] = {true, true};
  for (int i = 2; m < MAXL; i++) {
    if (!c[i]) {
      for (int j = 2; i * j < MAX; j++)
        c[i * j] = true;
      d[m++] = i;
    }
  }

  for (int i = 0; i < MAXL; i++)
    for (int j = i; d[i] + d[j] < MAX - 3; j++)
      dp[d[i] + d[j]]++;
  while (cin >> n, n)
    cout << dp[n] << endl;
  return 0;
}