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

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

int main() {

  vector<int> list;

  bool sosu[50000] = {false};
  for (long long int i = 2; i < 50000; i++) {
    if (sosu[i] == false) {
      list.push_back(i);
      for (long long int j = i * 2; j < 50000; j += i) {
        sosu[j] = true;
      }
    }
  }

  int n;

  while (true) {

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

    int cnt = 0;

    for (int i = list.size() - 1; i >= 0; i--) {

      int k = n - list[i];
      if (k < 2)
        continue;

      int x = 0;
      int y = i;
      while (true) {

        int z = (x + y) / 2;

        if (k == list[z]) {
          cnt++;
          break;
        } else if (k < list[z]) {
          if (y == z) {
            if (x == y)
              break;
            y = x;
          } else {
            y = z;
          }
        } else {
          if (x == z) {
            if (x == y)
              break;
            x = y;
          } else {
            x = z;
          }
        }
      }
    }

    cout << cnt << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

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

int main() {

  vector<int> list;

  bool sosu[50000] = {false};
  for (long long int i = 2; i < 50000; i++) {
    if (sosu[i] == false) {
      list.push_back(i);
      for (long long int j = i * 2; j < 50000; j += i) {
        sosu[j] = true;
      }
    }
  }

  cout << list.size() << endl;

  int n;

  while (true) {

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

    int cnt = 0;

    for (int i = 0; i < list.size(); i++) {

      int k = n - list[i];
      if (k < list[i])
        break;

      for (int j = i; j < list.size(); j++) {

        if (k == list[j])
          cnt++;
        if (k < list[j])
          break;
      }
    }

    cout << cnt << endl;
  }

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

#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
using namespace std;

#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define ALL(v) (v).begin(), (v).end()
#define PB push_back
#define EPS 1e-8

static const double PI = 6 * asin(0.5);
typedef complex<double> P;
typedef long long ll;

bool prime[50010];
int n;

int main() {
  rep(i, 50010) prime[i] = true;
  prime[0] = prime[1] = false;
  for (int i = 2; i * i <= 50010; i++) {
    if (prime[i]) {
      for (int j = i * i; j < 50010; j += i) {
        prime[j] = false;
      }
    }
  }

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

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
using namespace std;

#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define ALL(v) (v).begin(), (v).end()
#define PB push_back
#define EPS 1e-8

static const double PI = 6 * asin(0.5);
typedef complex<double> P;
typedef long long ll;

bool prime[5010];
int n;

int main() {
  rep(i, 5010) prime[i] = true;
  prime[0] = prime[1] = false;
  for (int i = 2; i * i <= 5010; i++) {
    if (prime[i]) {
      for (int j = i * i; j < 5010; j += i) {
        prime[j] = false;
      }
    }
  }

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

#include <iostream>
#include <vector>

using namespace std;

int table[50000];
vector<int> prime;

int main() {
  for (int i = 2; i < 50000; i++) {
    if (table[i] == 0) {
      prime.push_back(i);
      for (int j = i; j < 50000; j += i) {
        table[j] = 2;
      }
      table[i] = 1;
    }
  }
  int n, size = prime.size();
  while (cin >> n && n != 0) {
    int ans = 0, num1, num2;
    for (int i = 0; i < size; i++) {
      num1 = prime[i];
      num2 = n - num1;
      if (num2 <= 0) {
        break;
      }
      if (num1 <= num2 && table[num2] == 1) {
        ans++;
      }
    }
    cout << ans << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;

bool table[50000];
vector<int> prime;

int main() {
  for (int i = 2; i < 50000; i++) {
    if (table[i] == false) {
      prime.push_back(i);
      for (int j = i; j < 50000; j += i) {
        table[j] = true;
      }
    }
  }
  int n, size = prime.size();
  while (cin >> n && n != 0) {
    int ans = 0;
    for (int i = 0; i < size; i++) {
      if (prime[i] > n) {
        break;
      }
      for (int j = i; j < size; j++) {
        if (prime[i] + prime[j] > n) {
          break;
        }
        if (prime[i] + prime[j] == n) {
          ans++;
        }
      }
    }
    cout << ans << endl;
  }

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

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

bool is_prime[50001];
vector<int> prime;

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

int main() {
  int N;
  eratos();
  while (cin >> N && N) {
    int count = 0;
    int size = prime.size();
    for (int i = 0; i < size; ++i) {
      if (prime[i] >= N)
        break;
      if (prime[i] * 2 == N)
        count += 2;
      else if (binary_search(prime.begin(), prime.end(), N - prime[i]))
        ++count;
    }
    if (count % 2 == 0)
      count /= 2;
    cout << count << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

bool is_prime[50001];
vector<int> prime;

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

int main() {
  int N;
  eratos();
  while (cin >> N && N) {
    int count = 0;
    int size = prime.size();
    for (int i = 0; i < size; ++i) {
      if (prime[i] >= N)
        break;
      for (int j = 0; j <= i; ++j) {
        int sum = prime[i] + prime[j];
        if (N == sum)
          ++count;
        else if (N < sum)
          break;
      }
    }
    cout << count << endl;
  }
  return 0;
}
Problem p00056 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define rep(i, n) for ((i) = 0; (i) < (int)(n); (i)++)
#define foreach(itr, c)                                                        \\
  for (__typeof((c).begin()) itr = (c).begin(); itr != (c).end(); itr++)
inline int in() {
  int x;
  scanf("%d", &x);
  return x;
}

bool isprime[50000];

void sieve(int n) {
  memset(isprime, 1, sizeof(isprime));
  isprime[0] = isprime[1] = false;
  for (int i = 2; i * i <= n; i++)
    if (isprime[i]) {
      for (int j = 2 * i; j <= n; j += i)
        isprime[j] = false;
    }
}

int main() {
  int i, j, k;
  int n;
  int res;

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

    res = 0;
    for (i = 2; 2 * i <= n; i++)
      if (isprime[i] && isprime[n - i])
        res++;
    printf("%d\\n", res);
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define rep(i, n) for ((i) = 0; (i) < (int)(n); (i)++)
#define foreach(itr, c)                                                        \\
  for (__typeof((c).begin()) itr = (c).begin(); itr != (c).end(); itr++)
inline int in() {
  int x;
  scanf("%d", &x);
  return x;
}

bool isprime[50000];

void sieve(int n) {
  memset(isprime, 1, sizeof(isprime));
  isprime[0] = isprime[1] = false;
  for (int i = 2; i * i <= n; i++)
    if (isprime[i]) {
      for (int j = 2 * i; j <= n; j += i)
        isprime[j] = false;
    }
}

int main() {
  int i, j, k;
  int n;
  int res;

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

    res = 0;
    rep(i, n) if (isprime[i]) {
      for (j = i; j < n; j++)
        if (isprime[j]) {
          if (i + j == n)
            res++;
        }
    }
    printf("%d\\n", res);
  }

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

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

int Prime[50000];

int isPrime(int n) {
  int sq = sqrt((double)n);
  if (n == 1)
    return 0;
  if (n == 2)
    return 1;
  for (int i = 2; i <= sq; ++i)
    if (n % i == 0)
      return 0;
  return 1;
}

int main() {
  int n, cnt;

  for (int i = 0; i < 50000; ++i) {
    Prime[i] = isPrime(i + 1);
  }

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

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

Error: TLE

Fixed submission:

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

int isPrime(int n) {
  int sq = sqrt((double)n);
  if (n == 1)
    return 0;
  if (n == 2)
    return 1;
  for (int i = 2; i <= sq; ++i)
    if (n % i == 0)
      return 0;
  return 1;
}

int main() {
  int n, cnt;

  while (cin >> n, n) {
    cnt = 0;
    if (isPrime(n - 2))
      ++cnt;
    for (int i = 3; i <= n / 2; i += 2) {
      cnt += isPrime(i) && isPrime(n - i);
    }

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

#include <iostream>
using namespace std;
int main() {
  bool a[50002] = {0};

  for (int i = 2; i < 25002; i++)
    for (int j = i; j * i < 50002; j++)
      a[i * j] = true;
  int n;
  while (cin >> n, n) {
    int co = 0;
    for (int i = 2; i <= n / 2; i++) {
      if ((!a[i]) && (!a[n - i]))
        co++;
    }
    cout << co << endl;
  }
}

Error: 0

Fixed submission:

#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
int main() {
  bool a[25002];
  for (int i = 2; i < 12002; i++) {
    for (int j = i; j * i < 25002; j++) {
      a[i * j] = true;
    }
  }
  int n;
  while (cin >> n) {
    if (n == 0)
      break;
    int co = 0;
    for (int i = 2; i <= n / 2; i++) {
      if ((a[i] == false) && (a[n - i] == false))
        co++;
    }
    cout << co << endl;
  }
}
Problem p00056 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  int n;
  const int max = 50000;
  int a[max];
  a[1] = 0;
  for (int i = 2; i < max; i++)
    a[i] = 1;
  for (int i = 2; i * i <= max; i++) {
    for (int j = 2; j * i <= max; j++) {
      a[i * j] = 0;
    }
  }
  while (cin >> n) {
    if (n == 0)
      break;
    int count = 0;
    if (n % 2 == 1) {
      if (a[n - 2]) {
        cout << 1 << endl;
      } else {
        cout << 0 << endl;
      }
    } else {
      for (int i = 2; i <= n - i; i++)
        if (a[i] && a[n - i])
          count++;
      cout << count << endl;
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

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

int main() {
  int n;
  while (cin >> n) {
    if (n == 0)
      break;
    int count = 0;
    if (n % 2 == 1) {
      if (is_sosu(n - 2)) {
        cout << 1 << endl;
      } else {
        cout << 0 << endl;
      }
    } else {
      for (int i = 2; i <= n - i; i++)
        if (is_sosu(i) && is_sosu(n - i))
          count++;
      cout << count << endl;
    }
  }
  return 0;
}
Problem p00056 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define reps(i, f, n) for (int i = f; i < int(n); i++)
#define rep(i, n) reps(i, 0, n)

const int PS = 50001;
int prime[PS];
int set_prime() {
  rep(i, PS) prime[i] = 1;
  prime[0] = prime[1] = 0;
  rep(i, PS) {
    if (prime[i] == 0)
      continue;
    for (int j = i * 2; j < PS; j += i)
      prime[j] = 0;
  }
}

int main() {
  set_prime();
  vector<int> s;
  rep(i, PS) if (prime[i] == 1) s.push_back(i);

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

    int sum = 0;
    rep(i, s.size()) {
      if (n - s[i] >= 0 && s[i] * 2 <= n && prime[n - s[i]] == 1) {
        sum++;
      }
    }
    int sum2 = 0;
    for (int i = 2; i * 2 <= n; i++) {
      if (prime[i] && prime[n - i])
        sum2++;
    }
    // if(sum!=sum2)printf("%d  (%d-%d)\\n",n,sum,sum2);
    printf("%d\\n", sum2);
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define reps(i, f, n) for (int i = f; i < int(n); i++)
#define rep(i, n) reps(i, 0, n)

const int PS = 50001;
int prime[PS];
int set_prime() {
  rep(i, PS) prime[i] = 1;
  prime[0] = prime[1] = 0;
  rep(i, PS) {
    if (prime[i] == 0)
      continue;
    for (int j = i * 2; j < PS; j += i)
      prime[j] = 0;
  }
}

int main() {
  set_prime();
  vector<int> s;
  rep(i, PS) if (prime[i] == 1) s.push_back(i);

  int n;
  while (cin >> n) {
    int sum = 0;
    rep(i, s.size()) {
      reps(j, i, s.size()) {
        if (s[i] + s[j] == n)
          sum++;
      }
    }
    printf("%d\\n", sum);
  }
}
Problem p00056 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <iostream>
using namespace std;
int prime(int n);
int main() {
  int a[50000];
  for (int j = 0; j < 50000; j++)
    a[j] = prime(j);

  int b;
Loop:
  while (true) {
    int count = 0;
    cin >> b;
    if (b == 0)
      break;
    for (int x = 2; x < b / 2 + 1; x++) {
      if (a[x] != 0) {
        if (x <= b - x) {
          if (a[x] + a[b - x] == b)
            count++;
        }
      }
    }
    cout << count << endl;
  }
}

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

Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>
using namespace std;
int prime(int n);
int main() {
  int a[50000];
  for (int j = 0; j < 50000; j++)
    a[j] = prime(j + 1);

  int b;
Loop:
  while (true) {
    int count = 0;
    cin >> b;
    if (b == 0)
      break;
    for (int x = 0; x < b / 2 + 1; x++) {
      if (a[x] != 0) {
        for (int y = x; y < b - 1; y++) {
          if (a[x] + a[y] == b)
            count++;
        }
      }
    }
    cout << count << endl;
  }
}

int prime(int n) {
  if (n == 1)
    return 0;
  if (n == 2 || n == 3)
    return n;
  if (n % 2 == 0)
    return 0;
  for (int i = 3; i < sqrt(n) + 2; i++) {
    if (n % i == 0)
      return 0;
  }
  return n;
}
Problem p00056 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {

  bool p[MAX];
  p[0] = p[1] = false;
  for (int i = 2; i < MAX; i++)
    p[i] = true;
  for (int i = 2; i < MAX; i++) {
    if (p[i]) {
      for (int j = i + i; j < MAX; j = j + i) {
        p[j] = false;
      }
    }
  }

  int cnt[MAX];
  for (int i = 0; i < MAX; i++)
    cnt[i] = 0;
  for (int i = 0; i < MAX; i++) {
    for (int j = i; i + j < MAX; j++) {
      if (p[i] && p[j])
        cnt[i + j]++;
    }
  }

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

Error: TLE

Fixed submission:

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

int main() {

  bool p[MAX];
  p[0] = p[1] = false;
  for (int i = 2; i < MAX; i++)
    p[i] = true;
  for (int i = 2; i < MAX; i++) {
    if (p[i]) {
      for (int j = i + i; j < MAX; j = j + i) {
        p[j] = false;
      }
    }
  }

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

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <queue>
#include <string>

using namespace std;
int main() {
  int prime[50001] = {0};
  prime[0] = -1;
  prime[1] = -1;
  int now = 2;
  while (now <= 50000) {
    if (prime[now] == -1) {
      now++;
    } else {
      prime[now] = 1;
      int del = now;
      while (1) {
        del += now;
        if (del > 50000)
          break;
        prime[del] = -1;
      }
      now++;
    }
  }
  int x;
  while (cin >> x) {
    if (x == 0)
      break;
    int count = 0;
    for (int i = 2; i <= x / 2; i++) {
      if (prime[i] == 1 && prime[x - i] == 1)
        count++;
    }
    cout << count << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <queue>
#include <string>

using namespace std;

int main() {
  int i_max = 50000;
  queue<int> prime_temp;
  queue<int> prime;
  for (int i = 2; i <= i_max; i++) {
    prime_temp.push(i);
  }
  while (prime_temp.empty() != true) {
    prime.push(prime_temp.front());
    // cout<<prime_temp.front()<<" "<<endl;
    int temp_top = prime_temp.front();
    int temp_size = prime_temp.size();
    for (int i = 0; i < temp_size; i++) {
      if (prime_temp.front() % temp_top == 0) {
        prime_temp.pop();
      } else {
        prime_temp.push(prime_temp.front());
        prime_temp.pop();
      }
    }
  }

  int x;
  while (cin >> x) {
    if (x == 0)
      break;
    int a[x];
    int b[x];
    queue<int> prime_use;
    prime_use = prime;
    int pos = 0;
    while (prime_use.front() < x && prime_use.empty() != true) {
      a[pos] = prime_use.front();
      b[pos] = prime_use.front();
      prime_use.pop();
      pos++;
    }
    int count = 0;
    for (int i = 0; i < pos; i++) {
      for (int j = i; j < pos; j++) {
        if (a[i] + b[j] == x)
          count++;
      }
    }
    cout << count << endl;
  }
}
Problem p00056 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  bool is_prime[1000000];

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

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

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

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

  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  bool is_prime[1000000];

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

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

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

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

#include <iostream>
using namespace std;

/** Problem0056 : Goldbach's Conjecture **/
#define MAX 50000
int main() {
  bool prime[MAX];
  int input, count;

  for (int i = 0; i < MAX; i++)
    prime[i] = true;

  prime[0] = false;
  prime[1] = false;

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

  while (1) {
    cin >> input;
    if (input == 0)
      break;

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

    cout << count << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

/** Problem0056 : Goldbach's Conjecture **/
#define MAX 50000
int main() {
  bool prime[MAX];
  int input, count;

  for (int i = 0; i < MAX; i++)
    prime[i] = true;

  prime[0] = false;
  prime[1] = false;

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

  while (1) {
    cin >> input;
    if (input == 0)
      break;

    count = 0;
    for (int i = input; i > 1; i--) {
      if (!prime[i])
        continue;
      for (int j = input; j >= i; j--) {
        if (!prime[j])
          continue;
        if (i + j == input)
          count++;
      }
    }

    cout << count << endl;
  }

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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

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

  return true;
}

int main() {
  set<int> primes;

  for (int i = 2; i <= 50000; i++) {
    if (isPrime(i)) {
      primes.insert(i);
    }
  }

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

    if (n == 0) {
      break;
    }

    int count = 0;

    for (set<int>::iterator it = primes.begin();
         *it <= n / 2 && it != primes.end(); it++) {
      if (primes.find(n - *it) != primes.end()) {
        count++;
      }
    }

    cout << count << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

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

  return true;
}

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

    if (n == 0) {
      break;
    }

    int count = 0;

    for (int i = 2; i <= n / 2; i++) {
      if (isPrime(i) && isPrime(n - i)) {
        count++;
      }
    }

    cout << count << endl;
  }

  return 0;
}