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

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

#define MAX 50000

bool is_prime[MAX + 1];

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

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

int main() {
  int n;

  Sieve();

  while (cin >> n, n) {
    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>
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 cnt = 0;
    for (int i = 2; i <= n / 2; i++) {
      if (isprime(i) && isprime(n - i)) {
        //	cout << "prime: " << i << ", " << n-i << endl;
        cnt++;
      }
    }
    cout << cnt << endl;
  }
  return 0;
}
Problem p00056 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <stack>
#include <vector>
using namespace std;

#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define PUSH(n, v)                                                             \\
  for (int i = 0; i < (n); i++) {                                              \\
    int j;                                                                     \\
    cin >> j;                                                                  \\
    v.push_back(j);                                                            \\
  }
#define ALL(v) v.begin(), v.end()
#define print(s) cout << (s) << endl

bool prs[50000];

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

void solve56(int n) {
  if (n % 2) {
    if (prs[n - 2])
      cout << 1 << endl;
    else
      cout << 0 << endl;
  } else if (n == 4) {
    cout << 1 << endl;
  } else {
    int cnt = 0;
    for (int i = 3; i <= n / 2; i += 2) {
      if (prs[i] && prs[n - i])
        cnt++;
    }
    cout << cnt << endl;
  }
}

int main() {
  for (int i = 3; i < 50000; i += 2) {
    if (pr(i))
      prs[i] = true;
  }
  int n;
  while (cin >> n, n) {
    solve56(n);
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <stack>
#include <vector>
using namespace std;

#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define PUSH(n, v)                                                             \\
  for (int i = 0; i < (n); i++) {                                              \\
    int j;                                                                     \\
    cin >> j;                                                                  \\
    v.push_back(j);                                                            \\
  }
#define ALL(v) v.begin(), v.end()
#define print(s) cout << (s) << endl

bool prs[25000];

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

void solve56(int n) {
  if (n % 2) {
    if (prs[n - 2])
      cout << 1 << endl;
    else
      cout << 0 << endl;
  } else if (n == 4) {
    cout << 1 << endl;
  } else {
    int cnt = 0;
    for (int i = 3; i <= n / 2; i += 2) {
      if (prs[i] && prs[n - i])
        cnt++;
    }
    cout << cnt << endl;
  }
}

int main() {
  for (int i = 3; i < 25000; i += 2) {
    if (pr(i))
      prs[i] = true;
  }
  int n;
  while (cin >> n, n) {
    solve56(n);
  }
  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 += i) {
        is_prime[j] = false;
      }
    }
  }

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

    if (n == 0)
      break;
    int output = 0;

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


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {

  bool is_prime[50000];

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

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

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

    if (cin.eof())
      break;

    int output = 0;

    for (int i = 0; i < n; i++) {
      for (int j = 0; j <= i; j++) {
        if (is_prime[i] && is_prime[j])
          if ((i + j) == 10)
            output++;
      }
    }
    cout << output << endl;
  }
}
Problem p00056 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  int prime[50001];
  for (int i = 2; i < 50001; i++)
    prime[i] = 0;
  for (int i = 2; i <= sqrt(50001); i++) {
    if (prime[i] == 0) {
      for (int j = i + i; j < 50001; j += i)
        prime[j] = 1;
    }
  }
  int n, cou = 0;
  while (cin >> n && n != 0) {
    for (int i = 2; i <= n / 2; i++)
      if (prime[i] == 0 && prime[n - i] == 0)
        cou++;
    cout << cou << endl;
    cou = 0;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  char prime[50001];
  int co = 1, pri[6000];
  for (int i = 2; i < sqrt(50000); i++) {
    if (prime[i] != 1) {
      for (int j = 2; j * i < 50001; j++)
        prime[i * j] = 1;
    }
  }
  pri[0] = 2;
  for (int i = 3; i < 50000; i += 2) {
    if (prime[i] != 1) {
      pri[co] = i;
      co++;
    }
  }
  int n, cou = 0;
  while (cin >> n && n != 0) {
    if (n % 2 != 0)
      cout << "0" << endl;
    else {
      for (int i = 0; co > i; i++) {
        if (pri[i] > n / 2)
          break;
        for (int j = 0; co > j; j++) {
          if (pri[i] + pri[j] == n) {
            cou++;
            break;
          }
          if (pri[i] + pri[j] > n)
            break;
        }
      }
      cout << cou << endl;
      cou = 0;
    }
  }
}
Problem p00056 (C++) — buggy submission, verdict: Runtime Error

#include <cmath>
#include <iostream>

#include <string.h>

using namespace std;

bool prime_check(int n) {
  if (n == 1) {
    return false;
  }

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

    else {
      return false;
    }
  }

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

  return true;
}

int main() {
  const int DATA_SETS = 10000;
  const int MAX_PRIME = 50000;

  int N[DATA_SETS], P[DATA_SETS], C = 0;

  bool I[MAX_PRIME + 1];

  memset(N, 0, sizeof(N));
  memset(P, 0, sizeof(P));
  memset(I, 0, sizeof(I));

  for (int i = 1; i <= MAX_PRIME; i++) {
    if (prime_check(i) == true) {
      I[i] = true;
    } else {
      I[i] = false;
    }
  }

  while (true) {
    cin >> N[C];

    if (N[C] == 0) {
      goto Exit;
    }

    C++;
  }

Exit:;

  for (int i = 0; i < C; i++) {
    for (int j = 2; j <= N[i] / 2; j++) {
      if (I[j] == true && I[N[i] - j] == true) {
        P[i]++;
      }
    }

    cout << P[i] << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <cmath>
#include <iostream>

#include <string.h>

using namespace std;

bool prime_check(int n) {
  if (n == 1) {
    return false;
  }

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

    else {
      return false;
    }
  }

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

  return true;
}

int main() {
  const int DATA_SETS = 1000;
  const int MAX_PRIME = 50000;

  int N[DATA_SETS], P[DATA_SETS], C = 0;

  bool I[MAX_PRIME + 1];

  memset(N, 0, sizeof(N));
  memset(P, 0, sizeof(P));
  memset(I, 0, sizeof(I));

  for (int i = 1; i <= MAX_PRIME; i++) {
    if (prime_check(i) == true) {
      I[i] = true;
    } else {
      I[i] = false;
    }
  }

  while (true) {
    cin >> N[C];

    if (N[C] == 0) {
      goto Exit;
    }

    C++;
  }

Exit:;

  for (int i = 0; i < C; i++) {
    for (int j = 2; j <= N[i] / 2; j++) {
      if (I[j] == true && I[N[i] - j] == true) {
        P[i]++;
      }
    }

    cout << P[i] << endl;
  }

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

#include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#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 dump(n) cout << "# " << #n << "=" << (n) << endl
#define debug(n)                                                               \\
  cout << __FILE__ << "," << __LINE__ << ": # " << #n << "=" << (n) << endl
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, n) repi(i, 0, n)
#define iter(c) __typeof((c).begin())
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define allof(c) (c).begin(), (c).end()
#define mp make_pair

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

int main() {
  vi prime(1, 2);
  for (int i = 3; prime.back() <= 50000; i += 2) {
    bool ok = true;
    for (int j = 0; prime[j] * prime[j] <= i; j++)
      if (i % prime[j] == 0) {
        ok = false;
        break;
      }
    if (ok)
      prime.push_back(i);
  }

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

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#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 dump(n) cout << "# " << #n << "=" << (n) << endl
#define debug(n)                                                               \\
  cout << __FILE__ << "," << __LINE__ << ": # " << #n << "=" << (n) << endl
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, n) repi(i, 0, n)
#define iter(c) __typeof((c).begin())
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define allof(c) (c).begin(), (c).end()
#define mp make_pair

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

int main() {
  vi prime(1, 2);
  for (int i = 3; prime.back() <= 50000; i += 2) {
    bool ok = true;
    for (int j = 0; prime[j] * prime[j] <= i; j++)
      if (i % prime[j] == 0) {
        ok = false;
        break;
      }
    if (ok)
      prime.push_back(i);
  }

  for (int n; cin >> n, n;) {
    int res = 0;
    for (int i = 2; i <= n / 2; i++)
      if (binary_search(allof(prime), i) && binary_search(allof(prime), n - i))
        res++;
    cout << res << endl;
  }

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

#include <iostream>
using namespace std;
int main() {
  int list[50000];
  int i, j, c;
  for (i = 2; i < 50002; i++)
    list[i - 2] = i;
  for (j = 2; j * j < 50003; j++)
    if (list[j - 2] != 0)
      for (i = 1; j - 2 + list[j - 2] * i < 50001; i++)
        list[j - 2 + list[j - 2] * i] = 0;

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

Error: 0

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int list[32768];
  int i, j, c;
  for (i = 2; i < 32770; i++)
    list[i - 2] = i;
  for (j = 2; j * j < 32771; j++)
    if (list[j - 2] != 0)
      for (i = 1; j - 2 + list[j - 2] * i < 32769; i++)
        list[j - 2 + list[j - 2] * i] = 0;

  while (1) {
    cin >> i, c = 0;
    if (i == 0)
      break;
    for (j = 2; j <= (i / 2); j++)
      if ((list[j - 2] != 0) && (list[i - j - 2] != 0))
        c++;
    cout << c << "\\n";
  }
}
Problem p00056 (C++) — buggy submission, verdict: Time Limit Exceeded

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

vector<int> make() {
  bool b[50001] = {};
  for (int i = 2; i * i < 50001; ++i) {
    if (!b[i]) {
      for (int j = i * i; j < 50001; j += i) {
        b[j] = true;
      }
    }
  }
  vector<int> prime;
  prime.reserve(50000);
  for (int i = 2; i < 50001; ++i) {
    if (!b[i]) {
      prime.push_back(i);
    }
  }

  return prime;
}

int main() {
  int n;
  vector<int> prime = make();
  while (cin >> n, n) {
    int ans = 0;
    for (int i = 0; i < (int)prime.size(); ++i) {
      if (prime[i] > n)
        break;
      if (binary_search(prime.begin() + i, prime.end(), n - prime[i])) {
        ans++;
      }
    }
    cout << ans << endl;
  }
}

Error: TLE

Fixed submission:

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

vector<int> make() {
  bool b[50001] = {};
  for (int i = 2; i * i < 50001; ++i) {
    if (!b[i]) {
      for (int j = i * i; j < 50001; j += i) {
        b[j] = true;
      }
    }
  }
  vector<int> prime;
  prime.reserve(50000);
  for (int i = 2; i < 50001; ++i) {
    if (!b[i]) {
      prime.push_back(i);
    }
  }

  return prime;
}

int main() {
  int n;
  vector<int> prime = make();
  while (cin >> n, n) {
    int ans = 0;
    for (int i = 0; i < (int)prime.size(); ++i) {
      if (prime[i] > n)
        break;
      for (int j = i; j < (int)prime.size(); ++j) {
        if (prime[i] + prime[j] == n)
          ++ans;
      }
    }
    cout << ans << endl;
  }
}
Problem p00056 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
const int MAX = 50001;
using namespace std;

bool p[MAX];

void f() {
  for (int i = 0; i < MAX; i++) {
    p[i] = (i <= 1) ? false : true;
  }
  for (int i = 2; i <= MAX; i++) {
    if (p[i]) {
      for (int j = i * 2; j < MAX; j += i) {
        p[j] = false;
      }
    }
  }
}

int main() {
  int n;

  f();
  while (cin >> n, n) {
    int ans = 0;
    // if( n > 3 && n%2 == 0){
    for (int i = 2; i <= n / 2; ++i) {
      if (p[i] && p[n - i]) {
        // cout << n << " = " << p_[i] << " + " << n - p_[i] << endl;
        ans++;
      }
    }
    //}
    cout << ans << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>
const int MAX = 50001;
using namespace std;

bool p[MAX];
vector<int> p_;

void f() {
  for (int i = 0; i < MAX; i++) {
    p[i] = (i <= 1) ? false : true;
  }
  for (int i = 2; i * i <= MAX + 1; i++) {
    if (p[i]) {
      for (int j = i * 2; j < MAX; j += i) {
        p[j] = false;
      }
    }
  }
  for (int i = 2; i < MAX; ++i) {
    if (p[i])
      p_.push_back(i);
  }
}

int main() {
  int n;

  f();
  while (cin >> n, n) {
    int ans = 0;
    if (n < 4 || n % 2) {
      ans = 0;
    } else {
      for (int i = 0; i < p_.size() && p_[i] < n; ++i) {
        if (p[(n - p_[i])] && (n - p_[i]) >= p_[i]) {
          cout << n << " = " << p_[i] << " + " << n - p_[i] << endl;
          ans++;
        }
      }
    }
    cout << ans << endl;
  }
}
Problem p00056 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>

using namespace std;

const int SIEVE_SIZE = 100000;

bool sieve[SIEVE_SIZE + 1];
int prime[SIEVE_SIZE + 1];

int main() {
  int n;
  int i, j, cnt = 0;

  sieve[0] = sieve[1] = true;
  for (i = 2; i * i <= SIEVE_SIZE; i++) {
    if (sieve[i])
      continue;
    for (j = i * i; j <= SIEVE_SIZE; j += i) {
      sieve[j] = true;
    }
  }

  for (i = 0; i < SIEVE_SIZE; i++) {
    if (!sieve[i]) {
      prime[cnt++] = i;
    }
  }

  int sa;

  while (scanf("%d", &n), n != 0) {
    cnt = 0;

    for (i = 0; prime[i] <= n / 2; i++) {
      sa = n - prime[i];
      if (sieve[sa] == false) {
        cnt++;
      }
    }

    printf("%d\\n", cnt);
  }
}

Error: 0

Fixed submission:

#include <cstdio>
#include <vector>

using namespace std;

const int SIEVE_SIZE = 10000;

bool sieve[SIEVE_SIZE + 1];
int prime[SIEVE_SIZE + 1];

int main() {
  int n;
  int i, j, cnt = 0;

  sieve[0] = sieve[1] = true;
  for (i = 2; i * i <= SIEVE_SIZE; i++) {
    if (sieve[i])
      continue;
    for (j = i * i; j <= SIEVE_SIZE; j += i) {
      sieve[j] = true;
    }
  }

  for (i = 0; i < SIEVE_SIZE; i++) {
    if (!sieve[i]) {
      prime[cnt++] = i;
    }
  }

  int num = cnt;
  int sa;

  while (scanf("%d", &n), n != 0) {
    cnt = 0;

    for (i = 0; prime[i] <= n / 2; i++) {
      sa = n - prime[i];
      if (sieve[sa] == false) {
        cnt++;
      }
    }

    printf("%d\\n", cnt);
  }
}
Problem p00056 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

inline int to_int(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string to_str(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

typedef long long ll;

int main() {
  vector<int> primeList;
  bool used[50002];

  memset(used, true, sizeof(used));

  for (int i = 2; i <= sqrt(50000); i++) {
    if (used[i] == false) {
      continue;
    }
    for (int j = i * 2; j <= 50000; j += i) {
      used[j] = false;
    }
  }
  for (int i = 2; i < 50000; i++) {
    if (used[i] == true) {
      primeList.push_back(i);
    }
  }
  int num, ans;
  while (cin >> num) {
    if (num == 0) {
      break;
    }
    ans = 0;

    for (int i = 0; i < primeList.size() && primeList[i] <= (num / 2); i++) {
      if (used[num - primeList[i]] == true) {
        ans++;
      }
    }

    cout << ans << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

inline int to_int(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string to_str(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

typedef long long ll;

int main() {
  vector<int> primeList;
  bool used[50002];

  memset(used, true, sizeof(used));

  for (int i = 2; i <= sqrt(50000); i++) {
    if (used[i] == false) {
      continue;
    }
    for (int j = i * 2; j <= 50000; j += i) {
      used[j] = false;
    }
  }
  for (int i = 2; i < 50000; i++) {
    if (used[i] == true) {
      primeList.push_back(i);
    }
  }
  int num, ans;
  while (cin >> num) {
    if (num == 0) {
      break;
    }
    ans = 0;

    for (int i = 0; i < primeList.size(); i++) {
      if (num % 2 != 0 && i >= 1) {
        break;
      }
      for (int j = i; j < primeList.size(); j++) {
        if (primeList[i] + primeList[j] > num) {
          break;
        }
        if (primeList[i] + primeList[j] == num) {
          ans++;
        }
      }
    }

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

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

vector<int> p(0);

void Prime(int n) {

  bool flg[50000];
  int indx = 2;

  flg[0] = flg[1] = 0;
  for (int i = 0; i < n; i++)
    flg[i] = 0;

  while (indx < n) {
    flg[indx] = 1;
    p.push_back(indx);
    for (int i = 2; i * indx < n; i++) {
      flg[indx * i] = 1;
    }

    while (flg[indx] == 1 && indx < n)
      indx++;
  }
}

int main() {

  int n;
  int sum;

  Prime(50000);

  while (cin >> n, n) {

    sum = 0;

    for (int i = 0; i < (int)p.size(); i++) {
      if (p[i] >= n)
        break;

      if (binary_search(p.begin() + i, p.end(), n - p[i]) == true)
        sum++;
    }

    cout << sum << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

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

vector<int> p(0);

void Prime(int n) {

  bool flg[50000];
  int indx = 2;

  flg[0] = flg[1] = 0;
  for (int i = 0; i < n; i++)
    flg[i] = 0;

  while (indx < n) {
    flg[indx] = 1;
    p.push_back(indx);
    for (int i = 2; i * indx < n; i++) {
      flg[indx] = 1;
    }

    while (flg[indx] == 1 && indx < n)
      indx++;
  }
}

int main() {

  int n;
  int sum;

  Prime(50000);

  while (cin >> n, n) {

    sum = 0;

    if (n % 2 == 0) {

      for (int i = 0; i < (int)p.size(); i++) {
        if (p[i] >= n)
          break;

        for (int j = i; j < (int)p.size(); j++) {
          if (p[i] + p[j] == n) {
            sum++;
            break;
          }
        }
      }
    }

    cout << sum << endl;
  }

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

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

#define SIZE 50001

int main() {
  bool prime[SIZE];
  fill(prime, prime + SIZE, true);
  prime[0] = prime[1] = false;
  for (int i = 2; i * i < SIZE; i++) {
    for (int j = 2; j * i < SIZE; j++) {
      if (!prime[i * j])
        continue;
      prime[i * j] = false;
    }
  }

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

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

Error: TLE

Fixed submission:

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

#define SIZE 50001

int main() {
  bool prime[SIZE];
  fill(prime, prime + SIZE, true);
  prime[0] = prime[1] = false;
  for (int i = 2; i * i < SIZE; i++) {
    for (int j = 2; j * i < SIZE; j++) {
      if (!prime[i * j])
        continue;
      prime[i * j] = false;
    }
  }

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

    count = 0;
    for (int i = 2; i < n; i++) {
      if (!prime[i])
        continue;
      for (int j = i; j < n; j++) {
        if (!prime[j])
          continue;
        if (i + j == n)
          count++;
        if (i + j > n)
          break;
      }
    }
    cout << count << endl;
  }
  return 0;
}