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

#include <bits/stdc++.h>

using namespace std;

const int MAX = 1000100;
bool prime[MAX];

void sieve() {
  fill(prime, prime + MAX, true);
  prime[0] = prime[1] = false;

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

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

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

const int MAX = 1000100;
bool prime[MAX];

void sieve() {
  fill(prime, prime + MAX, true);
  prime[0] = prime[1] = false;

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

int main() {
  sieve();
  int n;
  while (cin >> n, n) {
    int ret = 0;
    for (int i = 0; i < n; i++) {
      for (int j = i; j < n; j++)
        if (prime[i] && prime[j] && i + j == n)
          ret++;
    }
    cout << ret << endl;
  }
}
Problem p00056 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <string>
#include <utility>
#include <vector>

typedef long long int ll;

using namespace std;

vector<int> p(50010, 1);
int n;

void calc() {
  for (int i = 0; i < 50010; i++) {
    if (i < 2)
      p[i] = 0;
    else {
      for (int j = 2; j <= sqrt(i); j++) {
        if (i % j == 0) {
          p[i] = 0;
          break;
        }
      }
    }
  }
}

int f() {
  int a = 0;
  for (int i = 0; i <= n / 2; i++) {
    if (p[i] && p[n - i])
      a++;
  }
  return a;
}

int main() {
  calc();
  while (1) {
    cin >> n;
    if (n == 0)
      break;
    cout << f() << endl;
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <string>
#include <utility>
#include <vector>

using namespace std;

vector<int> flag(2010, 1);

void getp() {
  for (int i = 0; i < flag.size(); i++) {
    if (i < 2)
      flag[i] = 0;
    else {
      for (int j = 2; j <= sqrt(i); j++) {
        if (i % j == 0) {
          flag[i] = 0;
          break;
        }
      }
    }
  }
}

int main() {
  int a;
  getp();
  while (1) {
    cin >> a;
    if (a == 0)
      break;
    int cnt = 0;
    for (int i = 2; i <= a / 2; i++) {
      if (flag[i] && flag[a - i])
        cnt++;
    }
    cout << cnt << endl;
  }
}
Problem p00056 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
bool so[50001] = {};

int main() {
  so[0] = 1;
  so[1] = 1;
  for (int i = 2; i * i <= 50000; i++)
    if (so[i] == 0)
      for (int j = 2; j * i <= 50000; j++)
        so[i * j] = 1;
  int n;
  while (cin >> n && n) {
    int co = 0;
    for (int i = 2; i <= n / 2; i++)
      if (so[i] == 0 && so[n - i] == 0)
        co++;
    cout << co << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

bool *isPrime;

vector<int> CreatePrimes(int n) {
  bool *work = new bool[n + 1];

  fill(work, work + (n + 1), true);
  work[0] = work[1] = false;

  vector<int> res;
  res.push_back(2);
  for (int i = 4; i <= n; i += 2)
    work[i] = false;

  for (int i = 3; i <= n; i += 2) {
    if (work[i]) {
      res.push_back(i);
      for (int j = 2 * i; j <= n; j += i)
        work[j] = false;
    }
  }

  isPrime = work;

  return res;
}

int main() {
  vector<int> primes = CreatePrimes(50000);
  while (true) {
    int n;
    scanf("%d\\n", &n);
    if (n == 0)
      break;

    int c = 0;
    for (int i = 2; i <= n / 2; ++i) {
      if (isPrime[i] && isPrime[n - i])
        ++c;
    }
    printf("%d\\n", c);
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

vector<int> CreatePrimes(int n) {
  bool *work = new bool[n + 1];

  fill(work, work + (n + 1), true);
  work[0] = work[1] = false;

  vector<int> res;
  res.push_back(2);
  for (int i = 4; i <= n; i += 2)
    work[i] = false;

  for (int i = 3; i <= n; i += 2) {
    if (work[i]) {
      res.push_back(i);
      for (int j = 2 * i; j <= n; j += i)
        work[j] = false;
    }
  }

  delete[] work;

  return res;
}

int main() {
  vector<int> primes = CreatePrimes(50000);
  while (true) {
    int n;
    scanf("%d\\n", &n);
    if (n == 0)
      break;

    int c = 0;
    vector<int>::iterator it = primes.begin();
    for (int i = 0; i < primes.size() && primes[i] < n; ++i) {
      if (binary_search(it, primes.end(), n - primes[i])) {
        ++c;
        ++it;
      }
    }
    printf("%d\\n", c);
  }

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

#include <cmath>
#include <iostream>
using namespace std;
int x[100000], y[100000], n, sum;
int main() {
  for (int i = 2; i < 100000; i++) {
    for (int j = 2; j <= sqrt(i); j++) {
      if (i % j == 0) {
        goto E;
      }
    }
    x[i] = 1;
  E:;
  }
  while (true) {
    cin >> n;
    sum = 0;
    if (!n) {
      break;
    }
    for (int i = 2; i <= n / 2; i++) {
      if (x[i] == 1 && x[n - i] == 1) {
        sum++;
      }
    }
    cout << sum << endl;
  }
}

Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>
using namespace std;
int x[100000], y[100000], n, sum;
int main() {
  for (int i = 2; i < 100000; i++) {
    for (int j = 2; j <= sqrt(i); j++) {
      if (i % j == 0) {
        goto E;
      }
    }
    x[i] = 1;
  E:;
  }
  while (true) {
    cin >> n;
    sum = 0;
    for (int i = 2; i < n; i++) {
      if (x[i] == 1 && x[n - i] == 1) {
        sum++;
      }
    }
    cout << sum << endl;
  }
}
Problem p00056 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

void sieve(bool *pn) {
  for (int i = 2; i < sqrt(50100.); ++i) {
    if (pn[i]) {
      for (int j = i * 2; j <= 50100; j += i) {
        pn[j] = false;
      }
    }
  }
}

int main() {
  bool pn[50100];
  int ans[50001];
  memset(pn, true, sizeof(pn));
  pn[0] = pn[1] = false;
  sieve(pn);
  int i, j = 2, n, len = 0;
  for (i = 0; i <= 50000; ++i) {
    if (pn[i])
      len++;
  }
  int *prime = new int[len];
  for (i = 0; i < len; ++i) {
    while (1) {
      if (pn[j]) {
        prime[i] = j;
        j++;
        break;
      }
      j++;
    }
  }
  for (i = 0; prime[i] <= 25000; ++i) {
    for (j = i; prime[i] + prime[j] <= 50000; ++j) {
      ans[prime[i] + prime[j]]++;
    }
  }

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

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

void sieve(bool *pn) {
  for (int i = 2; i < sqrt(50100.); ++i) {
    if (pn[i]) {
      for (int j = i * 2; j <= 50100; j += i) {
        pn[j] = false;
      }
    }
  }
}

int main() {
  bool pn[50100];
  bool used[5200];
  memset(pn, true, sizeof(pn));
  memset(used, false, sizeof(used));
  pn[0] = pn[1] = false;
  sieve(pn);
  int i, j = 2, n, cnt = 0, len = 0;
  for (i = 0; i <= 50000; ++i) {
    if (pn[i])
      len++;
  }
  int *prime = new int[len];
  for (i = 0; i < len; ++i) {
    while (1) {
      if (pn[j]) {
        prime[i] = j;
        j++;
        break;
      }
      j++;
    }
  }

  while (cin >> n && n) {
    cnt = 0;
    for (i = 0; i < len; ++i) {
      for (j = 0; j < len; ++j) { // len:5133
        if (prime[i] + prime[j] == n && !used[j]) {
          cnt++;
          used[i] = true;
          break;
        }
        if (prime[j] > n)
          break;
      }
      if (prime[i] > n)
        break;
    }
    cout << cnt << endl;
    memset(used, false, sizeof(used));
  }
  delete[] prime;
  return 0;
}
Problem p00056 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  const int MAX_P = 50000;
  bool p[MAX_P];
  for (int i = 0; i < MAX_P; ++i)
    p[i] = true;
  p[0] = p[1] = false;

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

  int n;
  while (~scanf("%d", &n)) {
    if (n == 0)
      break;

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

Error: TLE

Fixed submission:

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

int main() {
  const int MAX_P = 50000;
  bool p[MAX_P];
  for (int i = 0; i < MAX_P; ++i)
    p[i] = true;
  p[0] = p[1] = false;

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

  vector<int> prime;
  for (int i = 0; i < MAX_P; ++i) {
    if (p[i])
      prime.push_back(i);
  }

  int n;
  while (~scanf("%d", &n)) {
    if (n == 0)
      break;

    int ans = 0;
    for (unsigned int i = 0; i < prime.size(); ++i) {
      for (unsigned int j = i; j < prime.size(); ++j) {
        if (n == prime[i] + prime[j])
          ++ans;
      }
    }
    printf("%d\\n", ans);
  }
  return 0;
}
Problem p00056 (C++) — buggy submission, verdict: Runtime Error

#include <bitset>
#include <stdio.h>
int main() {
  const int N = 50001;
  int i, j, n, c;
  std::bitset<N> p(3);
  p.flip();
  for (i = 2; i * i < N; ++i)
    if (p[i])
      for (j = i * 2; j < N; j += i)
        p[j] = 0;
  while (scanf("%d", &n), n) {
    for (c = i = 0, j = n; i <= j; ++i, --j)
      if (p[i] && p[j])
        ++c;
    printf("%d\\n", c);
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bitset>
#include <stdio.h>
int main() {
  const int N = 5001;
  int i, j, n, c;
  std::bitset<N> p(3);
  p.flip();
  for (i = 2; i * i < N; ++i)
    if (p[i])
      for (j = i * 2; j < N; j += i)
        p[j] = 0;
  while (scanf("%d", &n), n) {
    for (c = i = 0, j = n; i <= j; ++i, --j)
      if (p[i] && p[j])
        ++c;
    printf("%d\\n", c);
  }
  return 0;
}
Problem p00056 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int main() {
  bool p[50001];
  memset(p, 1, sizeof(p));
  p[0] = p[1] = 0;
  for (int i = 0; i < 50001; i++) {
    if (p[i]) {
      for (int j = 2 * i; j < 50001; j += i) {
        p[j] = 0;
      }
    }
  }

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

Error: TLE

Fixed submission:

#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int main() {
  bool p[50001];
  memset(p, 1, sizeof(p));
  p[0] = p[1] = 0;
  for (int i = 0; i < 50001; i++) {
    if (p[i]) {
      for (int j = 2 * i; j < 50001; j += i) {
        p[j] = 0;
      }
    }
  }

  int n, sum;
  while (cin >> n, n) {
    int cnt = 0;
    for (int i = 0; i < n; i++) {
      for (int j = i; j < n; j++) {
        if (p[i] == 1 && p[j] == 1) {
          sum = i + j;
          if (sum == n)
            cnt++;
        }
      }
    }
    cout << cnt << endl;
  }
  return 0;
}
Problem p00056 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using namespace std;

// vector<int> prime;
int prime[50001];
int psize;
bool isPrime[50001];

void erats() {
  fill(isPrime, isPrime + 50001, true);
  isPrime[0] = false;
  isPrime[1] = false;
  for (int i = 2; i < 50001; i++) {
    if (isPrime[i]) {
      //			prime.push_back(i);
      prime[psize] = i;
      psize++;
      for (int j = i * 2; j < 50001; j += i) {
        isPrime[j] = false;
      }
    }
  }
}

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

    // for(int i = 0; i < psize; i++){
    //	if(prime[i]+prime[i]>n)
    //		break;
    //	for(int j = i; j < psize; j++){
    //		int sum=prime[i]+prime[j];
    //		if(sum>n)
    //			break;
    //		if(sum==n)
    //			cnt++;
    //	}
    // }
    cout << cnt << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

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

using namespace std;

// vector<int> prime;
int prime[50001];
int psize;
bool isPrime[50001];

void erats() {
  fill(isPrime, isPrime + 50001, true);
  isPrime[0] = false;
  isPrime[1] = false;
  for (int i = 2; i < 50001; i++) {
    if (isPrime[i]) {
      //			prime.push_back(i);
      prime[psize] = i;
      psize++;
      for (int j = i * 2; j < 50001; j += i) {
        isPrime[j] = false;
      }
    }
  }
}

int main() {
  psize = 0;
  erats();
  int n;
  while (cin >> n && n != 0) {
    int cnt = 0;
    for (int i = 0; i < psize; i++) {
      if (prime[i] + prime[i] > n)
        break;
      for (int j = i; j < psize; j++) {
        int sum = prime[i] + prime[j];
        if (sum > n)
          break;
        if (sum == n)
          cnt++;
      }
    }
    cout << cnt << endl;
  }

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

#include <algorithm>
#include <iostream>
#define N 50000
using namespace std;

int main() {
  bool ip[N];
  int p[N];
  for (int i = 0; i < N; i++)
    ip[i] = true;
  int q = 0;
  ip[0] = ip[1] = false;
  for (int i = 0; i < N; i++) {
    if (ip[i]) {
      p[q++] = i;
      for (int j = i * 2; j < N; j += i)
        ip[j] = false;
    }
  }
  int n, a;
  while (1) {
    cin >> n;
    a = 0;
    if (n == 0)
      break;
    if (n % 2) {
      if (binary_search(p, p + q, n - 2))
        a = 1;
    } else {
      for (int i = 0; p[i] <= n / 2; i++) {
        if (binary_search(p + i, p + q, n - p[i]))
          a++;
      }
    }
    cout << a << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#define N 50000
using namespace std;

int main() {
  bool ip[N];
  int p[N];
  for (int i = 0; i < N; i++)
    ip[i] = true;
  int q = 0;
  ip[0] = ip[1] = false;
  for (int i = 0; i < N; i++) {
    if (ip[i]) {
      p[q++] = i;
      for (int j = i * 2; j < N; j += i)
        ip[j] = false;
    }
  }
  int n, a;
  while (1) {
    cin >> n;
    a = 0;
    if (n == 0)
      break;
    if (n % 2) {
      if (find(p, p + q, n - 2) != p + q)
        a = 1;
    } else {
      for (int i = 0; p[i] <= n / 2; i++) {
        if (find(p + i, p + q, n - p[i]) != p + q)
          a++;
      }
    }
    cout << a << endl;
  }
  return 0;
}
Problem p00056 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

const int MAX = 50001;
using namespace std;

int main(void) {
  int i = 3;
  int n = 0;
  int ps[MAX];

  for (int i = 0; i < MAX; i++) {
    ps[i] = 1;
  }
  for (int i = 2; i < MAX; i++) {
    if (ps[i]) {
      for (int j = 2; i * j < MAX; j++) {
        ps[i * j] = 0;
      }
    }
  }

  while (1) {
    int n;
    int cnt = 0;

    cin >> n;
    if (n == 0)
      break;

    if (n % 2 == 1) {
      if (ps[n - 2])
        cnt++;
    } else {
      for (int i = 2; i <= n / 2; i++) {
        if (ps[i] && ps[n - i])
          cnt++;
      }
    }

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

Error: TLE

Fixed submission:

#include <iostream>

const int MAX = 5133;
using namespace std;

bool binsearch(int *p, int n, int key) {
  int l = 0;
  int r = n;
  int m = 0;

  while (1) {
    if (r <= l)
      break;
    if (m == (l + r) / 2)
      return false;
    else
      m = (l + r) / 2;

    if (p[m] > key)
      r = m;
    if (p[m] == key)
      return true;
    if (p[m] < key)
      l = m;
  }
  return false;
}

int main(void) {
  int i = 3;
  int n = 0;
  int ps[MAX] = {
      0,
  };

  ps[n++] = 2;
  while (n < MAX) {
    bool Skip = false;
    for (int j = 0; j < n; j++) {
      if (i % ps[j] == 0) {
        Skip = true;
        break;
      }
    }
    if (!Skip)
      ps[n++] = i;
    i++;
  }

  while (1) {
    int n;
    int cnt = 0;

    cin >> n;
    if (n == 0)
      break;
    if (n % 2 != 0 || n < 4 || n > 50000) {
      cout << 0 << endl;
      continue;
    }

    for (int i = 2; i <= n / 2; i++) {
      if (binsearch(ps, MAX, i) && binsearch(ps, MAX, n - i))
        cnt++;
    }

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

#include <iostream>
#define STA 50000
using namespace std;

int prime[50001];

int main() {
  int n;
  int cnt;
  for (int i = 2; i <= STA / 2; i++) {
    for (int j = 2; i * j <= STA; j++) {
      prime[i * j] = 1;
    }
  }
  while (1) {
    cnt = 0;
    cin >> n;
    if (n == 0)
      break;
    for (int i = 2; i <= n / 2; i++) {
      if (prime[i] == 0 && prime[n - i] == 0)
        cnt++;
    }
    cout << cnt << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
#define STA 50000
using namespace std;

int prime[50001];

int main() {
  int n;
  int cnt;
  for (int i = 2; i <= STA / 2; i++) {
    for (int j = 2; i * j <= STA; j++) {
      prime[i * j] = 1;
    }
  }
  while (1) {
    cnt = 0;
    cin >> n;
    if (n == 0)
      break;
    for (int i = 2; i <= n / 2; i++) {
      if (prime[i] == 0) {
        for (int j = i; j <= n; j++) {
          if (i + j == n && prime[j] == 0)
            cnt++;
        }
      }
    }
    cout << cnt << endl;
  }
}
Problem p00056 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  bool is_prime[100000];
  is_prime[0] = is_prime[1] = false;
  for (int i = 2; i < 100000; i++) {
    is_prime[i] = true;
  }

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

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

    if (n == 0)
      break;

    int cnt = 0;

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

    cout << cnt << endl;
  }
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  bool is_prime[100000];
  is_prime[0] = is_prime[1] = false;
  for (int i = 2; i < 100000; i++) {
    is_prime[i] = true;
  }

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

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

    if (n == 0)
      break;

    int cnt = 0;

    for (int i = 0; i < n; i++) {
      if (!is_prime[i])
        continue;

      for (int j = i; j < n; j++) {
        if (is_prime[j])
          if (i + j == n)
            cnt++;
      }
    }

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

#include <cmath>
#include <iostream>
using namespace std;
bool pr[50001];
int prime[114514];
int length = 0;
void insert(int p) {
  prime[length] = p;
  pr[p] = true;
  length++;
  return;
}
int main() {
  insert(2);
  for (int i = 3; i <= 50000; i += 2) {
    for (int j = 0; j < length; j++)
      if (i % prime[j] == 0)
        goto cont;
      else if (prime[j] > sqrt(i))
        break;
    insert(i);
  cont:;
  }
  int n;
  while (cin >> n) {
    if (!n)
      return 0;
    int sum = 0;
    for (int i = 2; i <= n / 2; i++)
      if (pr[i] && pr[n - i])
        sum++;
    cout << sum << endl;
  }
}

Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>
using namespace std;
bool isprime(int n) {
  if (n == 2)
    return true;
  if (n % 2 == 0)
    return false;
  for (int i = 3; i <= sqrt(n); i += 2)
    if (n % i == 0)
      return false;
  return true;
}
int main() {
  int n;
  while (cin >> n) {
    if (!n)
      break;
    int sum = 0;
    for (int i = 2; i <= n / 2; i++)
      if (isprime(i) && isprime(n - i))
        sum++;
    cout << sum << endl;
  }
  return 0;
}
Problem p00056 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <iostream>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
using namespace std;

int main() {
  bool prime[100000];
  rep(i, 100000) prime[i] = true;
  prime[0] = false;
  prime[1] = false;
  loop(i, 2, 1000) {
    for (int j = i * 2; j < 100000; j += i) {
      prime[j] = false;
    }
  }
  int n;
  while (1) {
    cin >> n;
    if (n == 0)
      break;
    int cnt = 0;
    rep(i, n / 2 + 1) {
      if (prime[n - i] && prime[i]) {
        cnt++;
        // cout<<i<<" "<<n-i<<endl;
      }
    }
    cout << cnt << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
using namespace std;

int main() {
  bool prime[100000];
  rep(i, 100000) prime[i] = true;
  prime[0] = false;
  prime[1] = false;
  loop(i, 2, 100000) {
    for (int j = i * 2; j < 100000; j += i) {
      prime[j] = false;
    }
  }
  int n;
  while (1) {
    cin >> n;
    if (n == 0)
      break;
    int cnt = 0;
    rep(i, n / 2 + 1) {
      if (prime[n - i] && prime[i]) {
        cnt++;
        cout << i << " " << n - i << endl;
      }
    }
    cout << cnt << endl;
  }
  return 0;
}
Problem p00056 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>

using namespace std;

const int MAX = 50000;

void eratosthenes(bool *p) {
  for (int i = 0; i <= MAX; i++)
    p[i] = true;
  p[1] = false;
  for (int i = 2; i <= MAX; i++) {
    if (!p[i])
      continue;
    for (int d = 2; i * d <= MAX; d++)
      p[i * d] = false;
  }
}

int main() {
  int n;

  bool *is_prime = new bool[MAX + 1];
  if (is_prime == NULL)
    return 1;
  eratosthenes(is_prime);

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

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

    cout << count << endl;
  }

  delete[] is_prime;

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>

using namespace std;

const int MAX = 10000;

void eratosthenes(bool *p) {
  for (int i = 0; i <= MAX; i++)
    p[i] = true;
  p[1] = false;
  for (int i = 2; i <= MAX; i++) {
    if (!p[i])
      continue;
    for (int d = 2; i * d <= MAX; d++)
      p[i * d] = false;
  }
}

int main() {
  int n;

  bool is_prime[MAX + 1];
  eratosthenes(is_prime);

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

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

    cout << count << endl;
  }

  return 0;
}