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

#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <ctype.h>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int gcd(int a, int b) {
  if (b == 0) {
    return a;
  } else {
    return gcd(b, a % b);
  }
}

vector<int> prime(60000);
int k;

void primesearch(int x) {
  for (int i = 0; i < x; i++)
    prime[i] = i;
  prime[1] = 0;
  for (int j = 2; j < x; j++) {
    for (int n = 2; j * n < x; n++) {
      k = j * n;
      prime[k] = 0;
    }
  }
}

int main() {
  int n, ans;
  primesearch(50001);
  while (1) {
    cin >> n;
    if (n == 0)
      break;
    ans = 0;
    for (int p = 2; p < n; p++) {
      if (prime[p] != 0) {
        if (p > n - p)
          break;
        if (prime[n - p] != 0)
          ans++;
      }
    }
    cout << ans << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <ctype.h>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int gcd(int a, int b) {
  if (b == 0) {
    return a;
  } else {
    return gcd(b, a % b);
  }
}

vector<int> prime(60000);
int k;

void primesearch(int x) {
  for (int i = 0; i < x; i++)
    prime[i] = i;
  prime[1] = 0;
  for (int j = 2; j < x; j++) {
    for (int n = 2; j * n < x; n++) {
      k = j * n;
      prime[k] = 0;
    }
  }
}

int main() {
  int n, ans;
  primesearch(50001);
  while (1) {
    cin >> n;
    if (n == 0)
      break;
    ans = 0;
    for (int p = 2; p < n; p++) {
      if (prime[p] != 0) {
        for (int pp = 2; pp < n; pp++) {
          if (prime[pp] == n - p && prime[pp] != 0) {
            ans++;
            pp = n;
          }
        }
      }
    }
    if (ans != 0)
      ans--;
    cout << ans << endl;
  }
  return 0;
}
Problem p00056 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstring>
#include <iostream>

#define rep2(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) rep2(i, 0, n)
#define MEMZERO(x) memset(x, 0, sizeof(x))
#define MEMSET(x, y) memset(x, y, sizeof(x))

using namespace std;

bool isPrime[50000];
int prime[5150];
int count[50001];

void setPrime(bool *p, int n) {
  p[0] = p[1] = false;
  rep2(i, 2, n) {
    if (!p[i])
      continue;
    for (int j = i + i; j < n; j += i) {
      p[j] = false;
    }
  }
}

int main(void) {
  MEMZERO(prime);
  MEMSET(isPrime, true);
  setPrime(isPrime, 50000);
  int pnt = 1;
  prime[0] = 2;
  for (int i = 3; i < 50000; i += 2) {
    if (isPrime[i]) {
      prime[pnt++] = i;
    }
  }

  MEMZERO(::count);
  rep(i, pnt) {
    rep2(j, i, pnt) {
      int pp = prime[i] + prime[j];
      if (pp < 50001)
        ++(::count[pp]);
    }
  }

  int n;

  while (cin >> n, n) {
    cout << ::count[n] << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstring>
#include <iostream>

#define rep2(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) rep2(i, 0, n)
#define MEMZERO(x) memset(x, 0, sizeof(x))
#define MEMSET(x, y) memset(x, y, sizeof(x))

using namespace std;

bool isPrime[50000];
int prime[5150];

void setPrime(bool *p, int n) {
  p[0] = p[1] = false;
  rep2(i, 2, n) {
    if (!p[i])
      continue;
    for (int j = i + i; j < n; j += i) {
      p[j] = false;
    }
  }
}

int main(void) {
  MEMZERO(prime);
  MEMSET(isPrime, true);
  setPrime(isPrime, 50000);
  int pnt = 1;
  prime[0] = 2;
  for (int i = 3; i < 50000; i += 2) {
    if (isPrime[i]) {
      prime[pnt++] = i;
    }
  }

  int n;

  while (cin >> n, n) {
    int count = 0;

    rep(i, pnt) {
      rep2(j, i, pnt) {
        if (prime[i] + prime[j] == n) {
          ++count;
        }
      }
    }
    cout << count << endl;
  }
  return 0;
}
Problem p00056 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int prime[1000000];
int main() {
  fill(prime, prime + 1000000, 1);
  prime[0] = prime[1] = 0;
  for (int i = 2; i * i < 1000000; i++) {
    if (prime[i])
      for (int j = i * 2; j < 1000000; j += i)
        prime[j] = 0;
  }

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

Error: -11

Fixed submission:

#include <iostream>
using namespace std;
int pri[50001];

int main() {
  int prime[100000];
  fill(prime, prime + 100000, 1);
  prime[0] = prime[1] = 0;
  for (int i = 2; i * i < 100000; i++) {
    if (prime[i])
      for (int j = i * 2; j < 100000; j += i)
        prime[j] = 0;
  }

  int p = 0;

  for (int i = 0; p < 50001; i++) {
    if (prime[i])
      pri[p++] = i;
  }

  int ans[50100];
  for (int i = 0; i < 50100; i++)
    ans[i] = 0;

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

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

int main() {
  int n, prime[50000] = {0}, c;
  bool f = true;
  prime[2] = 1;
  for (int i = 3; i < 50000; ++i) {
    for (int j = 2; j <= sqrt(i); ++j) {
      if (i % j == 0)
        f = false;
    }
    if (f)
      prime[i] = 1;
    f = true;
  }
  while (cin >> n, n) {
    c = 0;
    for (int i = 0; i <= n / 2; ++i) {
      if (prime[i] == 1 && prime[n - i] == 1)
        ++c;
    }
    cout << c << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int prime[6500];

int main() {
  int a, b = 1, count;
  bool f = true;
  prime[0] = 2;
  for (int i = 3; i <= 50000; ++i) {
    for (int j = 2; j <= sqrt(i); ++j) {
      if (i % j == 0) {
        f = false;
        break;
      }
    }
    if (f) {
      prime[b] = i;
      ++b;
    }
    f = true;
  }
  while (cin >> a, a) {
    count = 0;
    if (a % 2 == 0) {
      for (int i = 0; i < 5133; ++i) {
        if (prime[i] > a)
          break;
        for (int j = i; j < 5133; ++j) {
          if (prime[i] + prime[j] == a)
            ++count;
          else if (prime[i] + prime[j] > a)
            break;
        }
      }
    }
    cout << count << endl;
  }
  return 0;
}
Problem p00056 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <iostream>

#define NMAX 50000
using namespace std;

int main(void) {

  int hurui[NMAX] = {0};
  int prime[NMAX] = {0};
  int dp[NMAX * 3] = {0};
  int cnt = 0;

  hurui[0] = 1, hurui[1] = 1;

  for (int i = 2; i < NMAX; i++) {
    if (hurui[i] == 0) {
      prime[cnt] = i;
      cnt++;
      for (int j = i * 2; j < NMAX; j += i) {
        hurui[j] = 1;
      }
    }
  }

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

  int n;

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

  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>
#include <string>

#define NMAX 50000 + 50
#define YES 0
#define NO 1

using namespace std;

int main(void) {

  int sosuu[NMAX];

  /*hurui*/
  int hurui[NMAX] = {YES};
  int cnt = 0;
  hurui[0] = NO, hurui[1] = NO;
  for (int i = 2; i < NMAX; i++) {
    if (hurui[i] == YES) {
      sosuu[cnt] = i;
      cnt++;
      for (int j = i + i; j < NMAX; j += i) {
        hurui[j] = NO;
      }
    }
  }

  /*solve*/
  int n;
  int dp[2][NMAX];

  while (1) {
    cin >> n;
    if (n == 0)
      break;
    dp[0][0] = 1, dp[1][0] = 0;

    for (int i = 1; i <= n; i++) {
      dp[0][i] = 0, dp[1][i] = 0;
    }

    cout << n << "," << sosuu[0] << endl;
    for (int i = 0; i < 2; i++) {
      for (int j = 0; sosuu[j] < n; j++) {
        for (int k = 0; k < n; k++) {
          if (dp[0][k] > 0) {
            if (k + sosuu[j] <= n) {
              dp[1][k]++;
              dp[1][k + sosuu[j]]++;
            }
          }
        }
      }
      for (int i = 0; i < n; i++) {
        dp[0][i] = dp[1][i];
        dp[1][i] = 0;
      }
    }
    cout << dp[1][n] - (dp[1][n] / 2) << endl;
  }

  return 0;
}
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 = j + i) {
        is_prime[j] = false;
      }
    }
  }

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

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

    cout << cnt << 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 = j + i) {
        is_prime[j] = false;
      }
    }
  }

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

    int a, b;
    int cnt = 0;
    for (int i = 3; i <= n / 2; i = i + 2) {
      if (is_prime[i]) {
        a = i;
        for (int j = 3; j <= n; j = j + 2) {
          if (is_prime[j]) {
            b = j;
            if (a + b == n) {
              cnt++;
            }
          }
        }
      }
    }
    if (n == 0)
      break;

    cout << cnt << endl;
  }

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

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

int prime[50010];

int isprime(int n) {
  if (n <= 1)
    return 0;

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

int main() {
  fill(prime, prime + 50010, -1);
  for (int i = 0; i < 50010; ++i) {
    if (prime[i] == -1) {
      prime[i] = isprime(i);
      if (prime[i] == 1 && i < 225)
        for (int j = i * i; j < 50010; j *= i)
          prime[j] = 0;
    }
  }

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

Error: 0

Fixed submission:

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

int prime[25010];

int isprime(int n) {
  if (n <= 1)
    return 0;

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

int main() {
  fill(prime, prime + 25010, -1);
  for (int i = 0; i < 25010; ++i) {
    if (prime[i] == -1) {
      prime[i] = isprime(i);
      if (prime[i] == 1)
        for (int j = i * i; j < 25010; j *= i)
          prime[j] = 0;
    }
  }

  int n;
  while (cin >> n, n) {
    int count = 0;
    for (int i = 2; i < n / 2; ++i)
      if (prime[i] && prime[n - i])
        count++;
    if (n % 2 == 0 && prime[n / 2])
      count++;
    cout << count << endl;
  }
}
Problem p00056 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = a; i >= n; i--)
#define INF 999999999
#define INF_M 2147483647
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;

vector<int> erat(int n) {
  vector<int> primes(n);
  for (int i = 2; i < n; ++i)
    primes[i] = i;
  for (int i = 2; i * i < n; ++i)
    if (primes[i])
      for (int j = i * i; j < n; j += i)
        primes[j] = 0;
  // ?´???°?????????vector???????´?????????´????????\\?????????????????? (0
  // ??§??????????´??????¨??????)
  primes.erase(remove(primes.begin(), primes.end(), 0), primes.end());
  return primes;
}

int main() {
  vector<int> v = erat(50000);
  int n;
  while (cin >> n) {
    if (n == 0)
      break;
    int ans = 0;
    rep(i, 0, v.size()) {
      if (v[i] > n / 2)
        break;
      else if ((n - v[i]) != 0 &&
               *lower_bound(v.begin(), v.end(), n - v[i]) == n - v[i])
        ans++;
    }
    cout << ans << endl;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = a; i >= n; i--)
#define INF 999999999
#define INF_M 2147483647
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;

bool isprime(int n) { //?´???°????????°true
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0)
      return false;
  }
  return n != 1;
}

vector<int> erat(int n) {
  vector<int> primes(n);
  for (int i = 2; i < n; ++i)
    primes[i] = i;
  for (int i = 2; i * i < n; ++i)
    if (primes[i])
      for (int j = i * i; j < n; j += i)
        primes[j] = 0;
  // ?´???°?????????vector???????´?????????´????????\\?????????????????? (0
  // ??§??????????´??????¨??????)
  primes.erase(remove(primes.begin(), primes.end(), 0), primes.end());
  return primes;
}

int main() {
  vector<int> v = erat(50000);
  int n;
  while (cin >> n) {
    if (n == 0)
      break;
    int ans = 0;
    rep(i, 0, v.size()) {
      if (v[i] > n / 2)
        break;
      else if ((n - v[i]) != 0 && isprime(n - v[i]))
        ans++;
    }
    cout << ans << endl;
  }
}
Problem p00056 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;

int main() {
  bool list[50001];
  list[0] = list[1] = true;
  for (int i = 2; i <= 50000; i++) {
    list[i] = false;
  }
  for (int i = 2; i <= 50000; i++) {
    if (!list[i]) {
      for (int j = 2; i * j <= 50000; j++) {
        list[i * j] = true;
      }
    }
  }
  int n;
  cin >> n;
  while (n) {
    if (n > 50000)
      for (;;)
        ;
    int sum = 0;
    for (int i = 2; i * 2 <= n; i++) {
      if (!list[i] && !list[n - i])
        sum++;
    }
    cout << sum << endl;
    cin >> n;
  }
}

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 true;
}
int main() {
  int n;
  cin >> n;
  while (n) {
    int sum = 0;
    for (int i = 1; i * 2 <= n; i++) {
      if (isPrime(i) && isPrime(n - i))
        sum++;
    }
    cout << sum << endl;
    cin >> n;
  }
}
Problem p00056 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;

int a[50001];

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

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;

vector<int> sosu;

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

void makeSosuTable() {
  for (int i = 2; i < 50000; i++) {
    if (isSosu(i))
      sosu.push_back(i);
  }
}

bool isSosu2(int n) {
  for (int i = 0; i < sosu.size(); i++) {
    if (sosu[i] > n)
      break;
    if (sosu[i] == n)
      return true;
  }
  return false;
}

int main(void) {
  makeSosuTable();
  while (1) {
    int n;
    cin >> n;
    if (n == 0)
      break;
    int ans = 0;
    for (int i = 0; i < sosu.size(); i++) {
      if (sosu[i] > n / 2)
        break;
      if (isSosu2(n - sosu[i]))
        ans++;
    }
    cout << ans << endl;
  }
}
Problem p00056 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <iostream>

using namespace std;

int sosu_f[50001];

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

int main(void) {
  int n;
  int count;

  era();

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

Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>

using namespace std;

int sosu[50001];
int sosu_f[50001];

int era(void) {
  int k = 0;
  sosu_f[0] = sosu_f[1] = 1;
  for (int i = 2; i <= 50000; i++) {
    if (!sosu_f[i]) {
      sosu[++k] = i;
      for (int j = i; j <= 50000; j += i) {
        sosu_f[j] = 1;
      }
    }
  }
  return k;
}

int main(void) {
  int n, sum, k;
  int count;

  k = era();

  while (cin >> n, n != 0) {
    count = 0;
    if (n % 2) {
      cout << '0' << endl;
      continue;
    }
    for (int i = 0; i <= k; i++) {
      if (n < sosu[i])
        break;
      for (int j = i; j <= k; j++) {
        sum = sosu[i] + sosu[j];
        if (n < sum)
          break;
        if (n == sum)
          count++;
      }
    }
    cout << count << endl;
  }
  return 0;
}
Problem p00056 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <cstring>

#define N 50000

using namespace std;

int main(void) {
  int p[N + 1] = {0};
  int n, ans;

  for (int i = 2; i < N; i++) {
    if (p[i] == -1)
      continue;
    p[i] = 1;
    for (int j = i * 2; j < N; j += i) {
      p[j] = -1;
    }
  }
  while (scanf("%d", &n), n) {
    ans = 0;
    for (int i = 2; i <= n / 2; i++) {
      if (p[i] == 1 && p[n - i] == 1) {
        ans++;
      }
    }
    printf("%d\\n", ans);
  }
  return 0;
}


Error: 0

Fixed submission:

#include <cstdio>
#include <cstring>

#define N 50

using namespace std;

int main(void) {
  int p[N + 1] = {0};
  int n, ans;

  for (int i = 2; i < N; i++) {
    if (p[i] == -1)
      continue;
    p[i] = 1;
    for (int j = i * 2; j < N; j += i) {
      p[j] = -1;
    }
  }
  while (scanf("%d", &n), n) {
    ans = 0;
    for (int i = 2; i <= n / 2; i++) {
      if (p[i] == 1 && p[n - i] == 1) {
        ans++;
      }
    }
    printf("%d\\n", ans);
  }
  return 0;
}
Problem p00056 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  int n;
  bool p[50001] = {false, false};

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

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

bool p[50001];

void prime() {

  for (int i = 0; i < 50001; i++) {
    p[i] = false;
  }

  p[2] = p[3] = p[5] = p[7] = true;

  for (int i = 2; i < 50001; i++) {
    if (i % 2 != 0 && i % 3 != 0 && i % 5 != 0 && i % 7 != 0) {
      p[i] = true;
    }
  }
}

int main() {
  int n;

  prime();

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

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

#include <iostream>
using namespace std;
typedef long long ll;
#define MAX 50004
int dp[MAX], d[MAX];

int main() {
  int n, m = 0;
  static bool c[MAX] = {true, true};
  for (ll i = 2; i < MAX; i++) {
    if (!c[i]) {
      for (ll j = 2; i * j < MAX; j++)
        c[i * j] = true;
      d[m] = i;
      m++;
    }
  }
  int f = 1;
  // for(int i = 2990;i < 3000;i++)cout << d[i] << " ";
  for (int i = 0; i < 3000; i++) {
    for (int j = i; d[i] + d[j] < MAX - 3; j++) {
      int dd = d[i] + d[j];
      dp[dd]++;
      // if(d[i] + d[j] == 2)cout << "fuck";
    }
  }
  // for(int i = 0;i < 30;i++)cout << dp[i] << " ";

  while (cin >> n, n) {
    cout << dp[n] << endl;
  }
  return 0;
}

Error: -11

Fixed submission:

#include <iostream>
using namespace std;
typedef long long ll;
#define MAX 50004
int dp[MAX], d[MAX];

int main() {
  int n, m = 0;
  static bool c[MAX] = {true, true};
  for (ll i = 2; i < MAX; i++) {
    if (!c[i]) {
      for (ll j = 2; i * j < MAX; j++)
        c[i * j] = true;
      d[m] = i;
      m++;
    }
  }
  int f = 1;
  // for(int i = 0;i < 10;i++)cout << d[i] << " ";
  for (int i = 0; i < 3000; i++) {
    for (int j = i; d[i] + d[j] < MAX; j++) {
      dp[d[i] + d[j]]++;
      // if(d[i] + d[j] == 2)cout << "fuck";
    }
  }
  // for(int i = 50;i < 60;i++)cout << dp[i] << " ";

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

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

bool ip[50001];
int table[50002];
vector<int> vec;

int main() {

  for (int i = 0; i < 50001; i++) {
    ip[i] = true;
  }

  ip[0] = ip[1] = false;

  table[0] = table[1] = 0;

  for (int i = 2; i <= 50001; i++) {
    table[i] = 0;
    if (ip[i]) {
      vec.push_back(i);
      for (int j = 2 * i; j <= 50001; j += i) {
        ip[j] = false;
      }
    }
  }

  int s = vec.size();

  for (int i = 0; i < s; i++) {
    for (int j = i; j < s; j++) {
      if (vec[i] + vec[j] <= 50000) {
        table[vec[i] + vec[j]]++;
      }
    }
  }

  while (1) {
    int n;

    cin >> n;

    if (n == 0)
      break;

    cout << table[n] << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

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

bool ip[50001];
vector<int> vec;

int main() {

  for (int i = 0; i < 50001; i++) {
    ip[i] = true;
  }

  ip[0] = ip[1] = false;

  for (int i = 2; i <= 50001; i++) {
    if (ip[i]) {
      vec.push_back(i);
      for (int j = 2 * i; j <= 50001; j += i) {
        ip[j] = false;
      }
    }
  }

  int s = vec.size();

  while (1) {
    int n;

    cin >> n;

    if (n == 0)
      break;

    int ans = 0;

    for (int i = 0; vec[i] <= n && i < s; i++) {
      for (int j = i; vec[j] <= n && j < s; j++) {
        if (vec[i] + vec[j] == n) {
          ans++;
        }
      }
    }

    cout << ans << endl;
  }

  return 0;
}