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

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  vector<int> primes;
  bool flag[50000];
  int ans[50001];
  fill(flag, flag + 50000, 0);
  fill(ans, ans + 50001, 0);
  for (int i = 2; i < 50000; ++i) {
    if (!flag[i]) {
      primes.push_back(i);
      for (int j = 0; j < primes.size(); ++j) {
        int tmp = primes[j] + primes[primes.size() - 1];
        if (tmp < 50001)
          ans[tmp]++;
      }
      for (int j = i * 2; j < 50000; j += i) {
        flag[j] = true;
      }
    }
  }

  int n;
  while (cin >> n, n) {
    /*if(n%2==1)
    {
            cout<<0<<endl;
            continue;
    }
    int ans=0;
    for(int i = 0; i < primes.size(); ++i)
    {
            if(n<primes[i]) break;
            for(int j = i; j < primes.size(); ++j)
            {
                    if(n<primes[j]) break;
                    if(primes[i]+primes[j]==n) ans++;
            }
    }*/
    cout << ans[n] << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  vector<int> primes(0);
  bool flag[50000];
  fill(flag, flag + 50000, 0);
  for (int i = 2; i < 50000; ++i) {
    if (!flag[i]) {
      primes.push_back(i);
      for (int j = i * 2; j < 50000; j += i) {
        flag[j] = true;
      }
    }
  }

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

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

int cnt;
vector<int> v;
int c[50001];
int ans[50001];

int judge(int n) {
  int c = 0;
  for (int i = 1; i <= sqrt(n); i++) {
    if (n % i == 0)
      c++;
  }
  if (c == 1)
    return 0;
  return 1;
}

void solve() {
  int c = 0;
  for (int i = 2; i <= 50000; i++) {
    if (judge(i) == 0) {
      // cout << i << endl;
      v.push_back(i);
    }
  }
}

int main() {

  solve();
  memset(c, -1, sizeof(c));

  int a, b;

  memset(ans, 0, sizeof(ans));
  for (int i = 0; i < v.size(); i++) {
    for (int j = i; j < v.size(), v[i] + v[j] <= 50000; j++) {
      //	  if(v[i] + v[j] == a) cnt++;

      ans[v[i] + v[j]]++;
    }
  }

  while (1) {
    scanf("%d", &a);
    if (a == 0)
      break;
    cnt = 0;
    // if(c[a] != -1) printf("%d\\n",c[a]);
    // else{

    printf("%d\\n", ans[a]);
    //  c[a] = cnt;
    // }
  }
}

Error: TLE

Fixed submission:

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

int cnt;
vector<int> v;

int judge(int n) {
  int c = 0;
  for (int i = 1; i <= sqrt(n); i++) {
    if (n % i == 0)
      c++;
  }
  if (c == 1)
    return 0;
  return 1;
}

void solve() {
  int c = 0;
  for (int i = 2; i <= 25000; i++) {
    if (judge(i) == 0) {
      // cout << i << endl;
      v.push_back(i);
    }
  }
}

int main() {

  solve();

  int a, b;
  while (cin >> a && a) {
    cnt = 0;
    for (int i = 0; i < v.size(), v[i] < a; i++) {
      for (int j = i; j < v.size(), v[j] < a; j++) {
        // cout << v[i] << " " << v[j] << endl;
        if (v[i] + v[j] == a)
          cnt++;
      }
    }
    cout << cnt << endl;
  }
}
Problem p00056 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n, prime[10000], flag[50005] = {}, cnt = 1;
  prime[0] = 2;
  flag[2] = 1;
  for (int i = 3; i < 50000; i += 2) {
    int k = 0;
    for (int j = 3; j <= sqrt(i); j++) {
      if (i % j == 0) {
        k = 1;
        break;
      }
    }
    if (!k) {
      flag[i] = 1;
      prime[cnt] = i;
      cnt++;
    }
  }
  while (1) {
    cnt = 0;
    cin >> n;
    if (!n)
      break;
    for (int i = 0; prime[i] <= n / 2; i++) {
      if (flag[n - prime[i]])
        cnt++;
    }
    cout << cnt << endl;
  }
}

Error: TLE

Fixed submission:

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

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

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

int main() {
  int x = 50000;
  int pn[50001];

  for (int i = 0; i < 50001; i++)
    pn[i] = 0;

  // 50000以下の素数を配列に格納
  for (int i = 2; i <= x; i++) {
    bool judge = true;
    for (int j = 2; j <= sqrt(i); j++) {
      if (i % j == 0) {
        judge = false;
        break;
      }
    }
    if (judge == true)
      pn[i] = i;
  }

  // 整数の入力
  int n;
  while (cin >> n) {
    if (n == 0)
      break;

    int cnt = 0;

    for (int i = 2; i <= n / 2; i++)
      if (pn[i] != 0 && pn[n - i] != 0)
        cnt++;

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


Error: TLE

Fixed submission:

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

bool find(int key, vector<int> p) {
  int left = 0, right = p.size();
  int mid;

  while (left < right) {
    mid = (left + right) / 2;

    if (p[mid] < key)
      left = mid + 1;
    else if (p[mid] > key)
      right = mid;
    else
      return true;
  }
  return false;
}

int main() {
  int x = 50000;
  vector<int> pn;

  // 50000以下の素数を配列に格納
  for (int i = 2; i <= x; i++) {
    bool judge = true;
    for (int j = 2; j <= sqrt(i); j++) {
      if (i % j == 0) {
        judge = false;
        break;
      }
    }
    if (judge == true)
      pn.push_back(i);
  }

  // 整数の入力
  int n;
  while (cin >> n) {
    if (n == 0)
      break;

    if (n % 2 != 0)
      cout << 0 << endl;
    else {
      // 方針：2つの素数の和がnとなる場合、(n-片方の素数)がもう一方の素数になるはず。これを探索して、処理効率化。
      int sum = 0;
      for (int i = 0; i < pn.size(); i++) {
        if (pn[i] >
            n / 2) // 整数nの半分を越えたら、組み合わせがかぶるので計算しない。
          break;
        if (find(n - pn[i], pn) == true) {
          // cout << n-pn[i] << " + " << pn[i] << " = " << n << endl;
          sum++;
        }
      }
      cout << sum << endl;
    }
  }
  return 0;
}
Problem p00056 (C++) — buggy submission, verdict: Time Limit Exceeded

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

bool prime[100010];
int ans[100010];
void countPrime();

int main() {
  int n;
  countPrime();
  while (cin >> n, n) {
    cout << ans[n] << endl;
  }
}

void countPrime() {
  memset(prime, true, 100001);
  memset(ans, 0, 100001);
  for (int i = 2; i * i <= 50000; i++) {
    if (prime[i]) {
      for (int j = i * i; j <= 50000; j = j + i) {
        prime[j] = false;
      }
    }
  }
  for (int i = 2; i < 50000 / 2 + 1; i++) {
    for (int j = i; j < 50000 + 1; j++) {
      if (prime[i] && prime[j]) {
        ans[i + j]++;
      }
    }
  }
}

Error: TLE

Fixed submission:

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

bool prime[100010];
void countPrime();

int main() {
  int n;
  countPrime();
  while (cin >> n, n) {
    int ans = 0;
    if (n % 2 != 0)
      cout << ans << endl;
    else {
      int ret = 0;
      for (int i = 1; i < n / 2 + 1; i++) {
        for (int j = i; j < n; j++) {
          if (i > j)
            continue;
          if (prime[i] && prime[j]) {
            if (i + j == n) {
              ret++;
              // cout << i << " " << j << endl;
            }
          }
        }
      }
      cout << ret << endl;
    }
  }
}

void countPrime() {
  for (int i = 0; i < 50000; i++)
    prime[i] = true;
  for (int i = 2; i * i <= 50000; i++) {
    if (prime[i]) {
      for (int j = i * i; j <= 50000; j = j + i) {
        prime[j] = false;
      }
    }
  }
}
Problem p00056 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  bool a[100000];

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

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

  while (true) {
    int m;
    cin >> m;
    int count = 0;

    if (m == 0) {
      break;
    }

    for (int i = 2; i <= m / 2; i++) {
      if (a[i]) {
        if (a[m - i]) {
          count++;
        }
      }
    }

    cout << count << endl;
  }

  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  bool a[50000];

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

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

  int count = 0;

  while (true) {
    int m;
    cin >> m;
    if (m % 2 == 1) {
      continue;
    }

    if (m == 0) {
      break;
    }

    for (int i = 2; i <= m / 2; i++) {
      if (a[i]) {
        for (int j = m / 2; j <= m; j++) {
          if (a[j]) {
            if (m - i == j) {
              count++;
              break;
            }
          }
        }
      }
    }

    cout << count << endl;
  }

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

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

#define REP(i, k, n) for (int i = k; i < n; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define MAX 1000000
#define pb push_back

using namespace std;

int prime[MAX];

int main() {
  prime[0] = prime[1] = 0;

  REP(i, 2, MAX) { prime[i] = 1; }

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

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

Error: TLE

Fixed submission:

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

#define REP(i, k, n) for (int i = k; i < n; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define MAX 1000000
#define pb push_back

using namespace std;

int prime[MAX];

int main() {
  prime[0] = prime[1] = 0;

  REP(i, 2, MAX) { prime[i] = 1; }

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

  int n;
  while (cin >> n && n) {
    int count = 0;
    vector<int> a;
    rep(i, n) {
      rep(j, n) {
        if (prime[i] == 1 && prime[j] == 1 && i + j == n) {
          if (a.empty()) {
            a.pb(i);
            a.pb(j);
            count++;
          } else {
            vector<int>::iterator ite = find(a.begin(), a.end(), i);
            vector<int>::iterator ite2 = find(a.begin(), a.end(), j);

            if (ite == a.end() && ite == a.end()) {
              a.pb(i);
              a.pb(j);
              count++;
            }
          }
        }
      }
    }
    cout << count << endl;
  }
  return 0;
}
Problem p00056 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using namespace std;

const int MAX = 50001;

int main(int argc, char *argv[]) {
  vector<bool> v(MAX, true);
  vector<int> num(MAX, 0);
  for (int i = 2; i < sqrt(MAX); ++i) {
    if (v[i]) {
      for (int j = 0; i * (j + 2) < MAX; ++j) {
        v[i * (j + 2)] = false;
      }
    }
  }
  for (int i = 2; i < MAX / 2 + 1; ++i) {
    if (v[i]) {
      for (int j = i; j < MAX; ++j) {
        if (v[j] && i + j <= MAX) {
          num[i + j]++;
        }
      }
    }
  }
  int n;
  while (cin >> n, n) {
    cout << num[n] << endl;
  }

  return 0;
}


Error: TLE

Fixed submission:

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

using namespace std;

const int MAX = 50001;

int main(int argc, char *argv[]) {
  vector<bool> v(MAX, true);
  for (int i = 2; i < sqrt(MAX); ++i) {
    if (v[i]) {
      for (int j = 0; i * (j + 2) < MAX; ++j) {
        v[i * (j + 2)] = false;
      }
    }
  }
  int n;
  while (cin >> n, n) {
    int ans = 0;
    for (int i = 2; i < n / 2 + 1; ++i) {
      if (v[i]) {
        for (int j = i; j < n; ++j) {
          if (v[j] && i + j == n) {
            ans++;
          }
        }
      }
    }
    cout << ans << endl;
  }

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

#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int p[60000];
  memset(p, 0, sizeof(p));
  for (int i = 2; i < 30000; i++)
    if (p[i] == 0)
      for (int j = i + i; j < 60000; j += i)
        p[j] = 1;
  int n;
  for (; cin >> n, n;) {
    int count = 0;
    for (int i = 2; i <= n / 2; i++)
      if (p[i] == 0 && p[n - i] == 0)
        count++;
    cout << count << endl;
  }
}

Error: TLE

Fixed submission:

#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int price[60000];
  memset(price, 0, sizeof(price));
  vector<int> p;
  for (int i = 2; i < 60000; i++)
    if (price[i] == 0) {
      p.push_back(i);
      for (int j = i + i; j < 60000; j += i)
        price[j] = 1;
    }
  int n;
  for (; cin >> n, n;) {
    int count = 0;
    if (price[n] != 0) {
      for (int i = 0; p[i] < n; i++)
        for (int j = i; p[i] + p[j] <= n; j++)
          if (p[i] + p[j] == n)
            count++;
    }
    cout << count << endl;
  }
}
Problem p00056 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
const int MA = 50000;
int p[100000], tcnt, ans[100000];
int main() {
  for (int i = 2; i <= 60000; i++) {
    bool f = 1;
    for (int j = 2; j * j <= i; j++)
      if (i % j == 0)
        f = 0;
    if (f)
      p[tcnt] = i, tcnt++;
  }
  for (int i = 0; i < MA; i++) {
    if (p[i] > MA)
      break;
    for (int j = 0; j < MA; j++) {
      if (p[i] + p[j] > MA)
        break;
      if (i > j)
        continue;
      ans[p[i] + p[j]]++;
    }
  }

  int n;
  while (cin >> n, n)
    cout << ans[n] << endl;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
int stoi(string x) {
  stringstream ss;
  ss << x;
  int tmp;
  ss >> tmp;
  return tmp;
}
string itos(int x) {
  stringstream ss;
  ss << x;
  return ss.str();
}
vector<int> prime;

int main() {
  for (int i = 2; i <= 100000; i++) {
    bool f = 1;
    for (int j = 2; j * j <= i; j++)
      if (i % j == 0)
        f = 0;
    if (f)
      prime.push_back(i);
  }
  int n;
  while (cin >> n, n) {
    int cnt = 0;
    for (int i = 0;; i++) {
      if (prime[i] > n)
        break;
      for (int j = 0;; j++) {
        if (i > j)
          continue;
        if (prime[i] + prime[j] > n)
          break;
        if (prime[i] + prime[j] == n)
          cnt++;
      }
    }
    cout << cnt << endl;
  }
  return 0;
}
Problem p00056 (C++) — buggy submission, verdict: Runtime Error

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

#define MAX 50000

int main(void) {
  bool p[MAX + 5];
  int i, j;

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

  int n;
  while (scanf("%d", &n)) {
    if (n == 0)
      break;
    int res = 0;
    for (i = 2; i <= (n / 2); i++) {
      if (p[i] && p[n - i])
        res++;
    }
    printf("%d\\n", res);
  }

  return (0);
}

Error: 0

Fixed submission:

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

#define MAX 25500

int main(void) {
  bool p[MAX];
  int i, j;

  for (i = 3; i < MAX; i++) {
    p[i] = true;
    if (i % 2 == 0)
      p[i] = false;
  }
  p[2] = true;
  for (i = 3; i < MAX; i += 2) {
    if (p[i]) {
      for (j = 2; (i * j) < MAX; j++) {
        p[i * j] = false;
      }
    }
  }

  int n;
  while (scanf("%d", &n)) {
    if (n == 0)
      break;
    int res = 0;
    for (i = 2; i <= (n / 2); i++) {
      if (p[i] && p[n - i])
        res++;
    }
    printf("%d\\n", res);
  }

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

#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

using namespace std;

int p[50001];
int prime() {
  for (int i = 0; i <= 50000; ++i)
    p[i] = 1;
  for (int j = 4; j <= 50000; j += 2)
    p[j] = 0;
  for (int i = 3; i <= 50000; ++i) {
    if (!p[i])
      continue;
    for (int j = i + i; j <= 50000; j += i)
      p[j] = 0;
  }
}
int solve(int n) {
  int ans = 0;
  int half = n / 2;
  if (p[n - 2])
    ++ans;
  if (n % 2 == 0) {
    for (int i = 3; i <= half; i += 2) {
      if (p[i] && p[n - i])
        ++ans;
    }
  }
  return ans;
}
int main() {
  int n;
  prime();
  while (cin >> n && n)
    cout << solve(n) << endl;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

using namespace std;

int prime(int n) {
  int i = 3;
  for (int i = 3; i * i <= n; i += 2) {
    if (n % i == 0)
      return false;
  }
  return true;
}
int solve(int n) {
  int ans = 0;
  int half = n / 2;
  if (n & 1 == 1) {
    if ((n - 2) & 1 == 1 && prime(n - 2))
      ++ans;
  } else {
    for (int i = 3; i <= half; i += 2) {
      if ((n - i) & 1 == 1 && prime(i) && prime(n - i))
        ++ans;
    }
  }
  return ans;
}
int main() {
  int n;
  while (cin >> n && n)
    cout << solve(n) << endl;
}
Problem p00056 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
int main() {
  int n;
  char prime[50001];
  for (int i = 0; i <= 50000; i++)
    prime[i] = 1;
  prime[0] = 0;
  prime[1] = 0;
  for (int i = 2; i <= 50000; i++) {
    if (!prime[i])
      continue;
    for (int j = i + i; j <= 50000; j += i)
      prime[j] = 0;
  }
  while (scanf("%d\\n", &n), n) {
    int cnt = 0;
    for (int i = 2; i <= n / 2; i++)
      if (prime[i] && prime[n - i])
        cnt++;
    printf("%d\\n", cnt);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <cmath>
#include <cstdio>
using namespace std;
bool isprime(int n) {
  for (int i = 3; i * i <= n; i += 2) {
    if (n % i == 0)
      return false;
  }
  return true;
}
int main() {
  int n;
  while (scanf("%d", &n) && n != 0) {
    int res = 0;
    if (n % 2 != 0 || n < 6) {
      printf("0\\n");
      continue;
    }
    for (int i = 3; i <= n / 2; i += 2)
      if (isprime(i) && isprime(n - i))
        res++;
    printf("%d\\n", res);
  }
}
Problem p00056 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#define m 52000
using namespace std;

bool ba[m + 1] = {true};
void cp() {
  int co = 0;
  for (int i = 0; i < m + 1; i++) {
    ba[i] = {true};
  }
  for (int i = 2; i * i <= 52000; i++) {
    if (ba[i]) {
      for (int j = i * i; j <= 52000; j += i) {
        ba[j] = {false};
      }
    }
  }

  return;
}

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

Error: TLE

Fixed submission:

#include <iostream>
#define m 52000
using namespace std;

bool ba[m + 1] = {true};
void cp() {
  int co = 0;
  for (int i = 0; i < m + 1; i++) {
    ba[i] = {true};
  }
  for (int i = 2; i * i <= 52000; i++) {
    if (ba[i]) {
      for (int j = i * i; j <= 52000; j += i) {
        ba[j] = {false};
      }
    }
  }

  return;
}

int main() {
  int n;
  while (cin >> n, n) {
    int c = 0;
    for (int i = 2; i <= n / 2; i++) {
      int j = n - i;

      cp();
      if (ba[i] == true && ba[j] == true)
        c++;
    }
    cout << c << endl;
  }
  return 0;
}
Problem p00056 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>
int main() {
  int isprime[50001] = {0};
  isprime[2] = 1;
  std::vector<int> v;
  v.push_back(2);
  for (int i = 3; i <= 50000; i += 2) {
    bool f = true;
    for (int j = 0; v[j] * v[j] <= i; j++) {
      if (i % v[j] == 0) {
        f = false;
        break;
      }
    }
    if (f) {
      v.push_back(i), isprime[i] = 1;
    }
  }

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

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>
int main() {
  int isprime[50001] = {0};
  isprime[2] = 1;
  std::vector<int> v;
  v.push_back(2);
  for (int i = 3; i <= 50000; i += 2) {
    bool f = true;
    for (int j = 0; v[j] * v[j] <= i; j++) {
      if (i % v[j] == 0) {
        f = false;
        break;
      }
    }
    if (f)
      v.push_back(i), isprime[i] = 1;
  }

  int n, res = 0;
  while (std::cin >> n, n) {
    res = 0;
    for (int i = 2; i <= n / 2; i++) {
      // for(int j=i;v[i]+v[j]<=n;j++){
      // 	if(v[i]+v[j] == n)res++;
      // }
      if (isprime[i] && isprime[n - i])
        res++;
      std::cout << i << "," << n - i << std::endl;
    }
    std::cout << res << std::endl;
  }

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

#include <iostream>
#include <string>

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 <iostream>
#include <string>

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;
  }
}