alexjercan/bugnet huggingface dataset:
Problem p00185 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

#define MN 1000001
bool pr[MN] = {0};

int main() {
  for (int i = 2; i < MN; i++) {
    pr[i] = 1;
  }
  for (int i = 2; i * i < MN; i++) {
    if (pr[i])
      for (int j = i * 2; j < MN; j += i) {
        pr[j] = 0;
      }
  }

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

Error: 0

Fixed submission:

#include <iostream>
using namespace std;

#define MN 500001
bool pr[MN] = {0};

int main() {
  for (int i = 2; i < MN; i++) {
    pr[i] = 1;
  }
  for (int i = 2; i * i < MN; i++) {
    if (pr[i])
      for (int j = i * 2; j < MN; j += i) {
        pr[j] = 0;
      }
  }

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

#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = n - 1; i >= 0; i--)

#define PB push_back
#define INF INT_MAX / 3
#define ALL(a) (a).begin(), (a).end()
#define CLR(a) memset(a, 0, sizeof(a))

typedef long long int ll;

using namespace std;

int main() {
  vector<int> primes;
  primes.PB(2);
  for (int i = 3; i <= 999991; i++) {
    bool flg = true;
    for (int j = 0; primes[j] * primes[j] <= i; j++) {
      if (i % primes[j] == 0) {
        flg = false;
        break;
      }
    }
    if (flg)
      primes.PB(i);
  }
  while (true) {
    int n;
    cin >> n;
    if (n == 0)
      break;
    int ans = 0;
    for (int i = 0; primes[i] <= n / 2; i++) {
      int j = lower_bound(ALL(primes), n - primes[i]) - primes.begin();
      if (primes[j] + primes[i] == n) {
        ans++;
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = n - 1; i >= 0; i--)

#define PB push_back
#define INF INT_MAX / 3
#define ALL(a) (a).begin(), (a).end()
#define CLR(a) memset(a, 0, sizeof(a))

typedef long long int ll;

using namespace std;

int main() {
  vector<int> primes;
  primes.PB(2);
  for (int i = 3; i <= 1e7; i++) {
    bool flg = true;
    for (int j = 0; primes[j] * primes[j] <= i; j++) {
      if (i % primes[j] == 0) {
        flg = false;
        break;
      }
    }
    if (flg)
      primes.PB(i);
  }
  while (true) {
    int n;
    cin >> n;
    if (n == 0)
      break;
    int ans = 0;
    for (int i = 0; primes[i] <= n / 2; i++) {
      int j = lower_bound(ALL(primes), n - primes[i]) - primes.begin();
      if (primes[j] + primes[i] == n) {
        ans++;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p00185 (C++) — buggy submission, verdict: Runtime Error

// 00
#include <iostream>

using namespace std;

int main() {
  static bool cmp[1000001] = {true, true};
  for (int i = 2; i < 1000001; i++) {
    if (!cmp[i]) {
      for (int j = 2; i * j < 1000001; j++) {
        cmp[i * j] = true;
      }
    }
  }
  for (int n; cin >> n, n;) {
    int ans = 0;
    for (int i = 0; i + i <= n; i++) {
      ans += !cmp[i] && !cmp[n - i];
    }
    cout << ans << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

// 00
#include <iostream>

using namespace std;

int main() {
  static bool cmp[500001] = {true, true};
  for (int i = 2; i < 500001; i++) {
    if (!cmp[i]) {
      for (int j = 2; i * j < 500001; j++) {
        cmp[i * j] = true;
      }
    }
  }
  for (int n; cin >> n, n;) {
    int ans = 0;
    for (int i = 0; i + i <= n; i++) {
      ans += !cmp[i] && !cmp[n - i];
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p00185 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, a, b) for (int i = (a); i < (b); i++)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

const int INF = 1 << 29;
const double EPS = 1e-9;

const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
bool prime[1000010];
void sieve() {
  for (int i = 1; i <= 1000000; i++) {
    prime[i] = true;
  }
  prime[1] = false;
  for (int i = 2; i * i <= 1000000; i++) {
    if (prime[i]) {
      for (int j = i * i; j <= 1000000; j += i) {
        prime[j] = false;
      }
    }
  }
}
int main() {
  int n;
  sieve();
  while (cin >> n, n) {
    int ans = 0;
    for (int i = 2; i <= n / 2; i++) {
      if (prime[i] && prime[n - i]) {
        ans++;
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, a, b) for (int i = (a); i < (b); i++)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

const int INF = 1 << 29;
const double EPS = 1e-9;

const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
bool prime[1000010];
void sieve() {
  for (int i = 1; i <= 1000000; i++) {
    prime[i] = true;
  }
  prime[1] = false;
  for (int i = 2; i * i <= 1000000; i++) {
    if (prime[i]) {
      for (int j = i * i; j <= 1000000; j += i) {
        prime[j] = false;
      }
    }
  }
}
int main() {
  int n;
  sieve();
  while (cin >> n, n) {
    int ans = 0;
    for (int i = 2; i <= n / 2; i++) {
      if (!prime[i])
        continue;
      for (int j = i; i + j <= n; j++) {
        if (!prime[j])
          continue;
        if (i + j == n) {
          ans++;
          // cout <<i<<" "<<j<<endl;
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p00185 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
#define MAX_N 1000001
int main() {
  int n;
  int isPrime[MAX_N];
  fill(isPrime, isPrime + MAX_N, 1);

  isPrime[0] = isPrime[1] = 0;

  for (int i = 2; i * i < MAX_N; i++) {
    if (isPrime[i]) {
      for (int j = i * 2; j < MAX_N; j += i)
        isPrime[j] = 0;
    }
  }

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

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
#define MAX_N 1000001
int main() {
  int n;
  int isPrime[MAX_N];
  fill(isPrime, isPrime + MAX_N, 1);

  isPrime[0] = isPrime[1] = 0;

  for (int i = 2; i * i < MAX_N; i++) {
    if (isPrime[i]) {
      for (int j = i * 2; j < MAX_N; j += i)
        isPrime[j] = 0;
    }
  }

  int p = 0;
  int ans[MAX_N] = {0};

  for (int i = 0; i < MAX_N; i++)
    if (isPrime[i])
      isPrime[p++] = i;

  for (int i = 0; i < p; i++) {
    for (int j = i; isPrime[i] + isPrime[j] < MAX_N; j++) {
      ++ans[isPrime[i] + isPrime[j]];
    }
  }

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

#include <iostream>
#define MAX 1000000

using namespace std;

int isprime[MAX];

void ERATOSUTENESUNOHURUI(void) {

  for (int i = 0; i < MAX; i++)
    isprime[i] = 1;
  isprime[0] = isprime[1] = 0;

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

int main(void) {

  ERATOSUTENESUNOHURUI();

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

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

Error: TLE

Fixed submission:

#include <iostream>
#define MAX 1000000

using namespace std;

int isprime[MAX];
int prime[80000] = {0};

void ERATOSUTENESUNOHURUI(void) {

  for (int i = 0; i < MAX; i++)
    isprime[i] = 1;
  isprime[0] = isprime[1] = 0;

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

int main(void) {

  ERATOSUTENESUNOHURUI();

  int I = 0;
  for (int i = 2; i < MAX; i++) {
    if (isprime[i]) {
      prime[I++] = i;
    }
  }
  I++;

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

    int cnt = 0;
    for (int i = 0; i < n; i++) {
      for (int j = i; j < n; j++) {
        if (i < I && j < I) {
          if (n == prime[i] + prime[j])
            cnt++;
        }
      }
    }
    cout << cnt << endl;
  }
  return 0;
}
Problem p00185 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
namespace AOJ0185 {
class Primes {
public:
  static void GetPrimes(int max, vector<int> &primes) {
    vector<bool> flags(max + 1, true);
    for (int i = 2; i <= max; i++) {
      if (flags[i]) {
        primes.push_back(i);
        for (int j = i; j <= max; j += i) {
          flags[j] = false;
        }
      }
    }
  }
};

class Solver {
private:
  static const int MAX_N = 1000001;
  int Input() {
    int n;
    cin >> n;
    return n;
  }

  void Output(int answer) { cout << answer << endl; }

public:
  void Solve() {
    vector<int> primes;
    Primes::GetPrimes(MAX_N, primes);

    int n;
    while (n = Input()) {
      int answer = 0;
      for (int i = 0; i < primes.size(); i++) {
        int diff = n - primes[i];
        if (diff < primes[i])
          break;
        bool exist = binary_search(primes.begin(), primes.end(), diff);
        if (exist)
          answer++;
      }
      Output(answer);
    }
  }
};
} // namespace AOJ0185

int main() { AOJ0185::Solver().Solve(); }


Error: TLE

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;
namespace AOJ0185 {
class Primes {
private:
  vector<int> primes;

public:
  Primes(int max) {
    vector<bool> flags(max + 1, true);
    for (int i = 2; i <= max; i++) {
      if (flags[i]) {
        primes.push_back(i);
        for (int j = i; j <= max; j += i) {
          flags[j] = false;
        }
      }
    }
  }

  int operator[](int index) { return primes[index]; }

  int size() { return primes.size(); }
};

class Solver {
private:
  static const int MAX_N = 1000001;
  int answers[MAX_N] = {};
  void CalcAnswers() {
    Primes primes(MAX_N);
    for (int i = 0; i < primes.size(); i++) {
      for (int j = i; j < primes.size(); j++) {
        int sum = primes[i] + primes[j];
        if (sum >= MAX_N)
          break;
        answers[sum]++;
      }
    }
  }

  int Input() {
    int n;
    cin >> n;
    return n;
  }

  void Output(int n) { cout << answers[n] << endl; }

public:
  void Solve() {
    CalcAnswers();
    int n;
    while (n = Input())
      Output(n);
  }
};
} // namespace AOJ0185

int main() { AOJ0185::Solver().Solve(); }
Problem p00185 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  bool prime[1000001];
  memset(prime, true, sizeof(prime));
  prime[0] = prime[1] = false;
  for (int i = 2; i <= 1000000; i++) {
    if (prime[i]) {
      for (int j = 2 * i; j <= 1000000; j += i)
        prime[j] = false;
    }
  }
  int n;
  while (cin >> n, n) {
    int cnt = 0;
    for (int i = 3; i <= n / 2; i += 2) {
      if (prime[i] && prime[n - i])
        cnt++;
    }
    cout << cnt << endl;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
bool is_prime(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 = 3; i <= n / 2; i += 2) {
      if (is_prime(i) && is_prime(n - i))
        cnt++;
    }
    cout << cnt << endl;
  }
}
Problem p00185 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>
int main() {
  int n;
  int i, j, k, sw, c;
  int a[1000001] = {};
  a[2] = 1;
  j = 1;
  for (i = 3; i < 1000000; i += 2) {
    sw = 0;
    for (k = 2; k * k <= i; k++) {
      if (a[k] == 1)
        if (i % k == 0) {
          sw = 1;
          break;
        }
    }
    if (sw == 0)
      a[i] = 1;
  }
  while (1) {
    scanf("%d", &n);
    if (n == 0)
      break;
    c = 0;
    for (i = 2; i <= n / 2; i++) {
      if (a[i] == 1)
        if (a[n - i] == 1)
          c++;
      if (i != 2)
        i++;
    }
    printf("%d\\n", c);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>
int main() {
  int n;
  int i, j, k, sw, c;
  int a[1000001] = {};
  a[2] = 1;
  j = 1;
  for (i = 3; i < 1000000; i += 2) {
    sw = 0;
    for (k = 2; k * k <= i; k++) {
      if (a[k] == 1)
        if (i % k == 0) {
          sw = 1;
          break;
        }
    }
    if (sw == 0)
      a[i] = 1;
  }
  while (1) {
    scanf("%d", &n);
    c = 0;
    for (i = 2; i <= n / 2; i++) {
      if (a[i] == 1)
        if (a[n - i] == 1)
          c++;
    }
    printf("%d\\n", c);
  }
  return 0;
}
Problem p00185 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int p[5000000];

bool prime(int x) {
  if (x == 2)
    return false;

  if (x < 1 || x % 2 == 0)
    return false;

  int i = 3;
  while (i <= sqrt(x)) {
    if (x % i == 0)
      return false;
    i += 2;
  }
  return true;
}

int main() {
  int n, ans;

  int j = 0;
  for (int i = 3; i <= 1000000; i++)
    if (prime(i))
      p[j++] = i;
  while (1) {
    ans = 0;
    cin >> n;
    if (n == 0)
      break;
    for (int i = 0; p[i] <= (n + 1) / 2; i++) {
      if (prime(n - p[i]))
        ans++;
    }
    cout << ans << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int p[5000000];

bool prime(int x) {
  if (x == 2)
    return false;

  if (x < 1 || x % 2 == 0)
    return false;

  int i = 3;
  while (i <= sqrt(x)) {
    if (x % i == 0)
      return false;
    i += 2;
  }
  return true;
}

int main() {
  int n, ans;

  int j = 0;
  for (int i = 3; i <= 1000000; i++)
    if (prime(i))
      p[j++] = i;
  while (1) {
    ans = 0;
    cin >> n;
    if (n == 0)
      break;
    for (int i = 0; p[i] < n; i++) {
      for (int j = i; p[j] < n; j++) {
        if (n == (p[i] + p[j])) {

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


#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>

using namespace std;

#define EPS (1e-10)
#define EQ(a, b) (abs((a) - (b)) < EPS)
#define EQV(a, b) (EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()))

typedef complex<double> P;
typedef long long ll;

const int MAX_SIZE = 10000;
const int MAX_PRIME = 1000000;

int prime[MAX_PRIME + 1];
bool isPrime[MAX_PRIME + 1];
int p;

void erats() {
  // primeツδ環スツトツづーツ渉可甘コツ可サ
  fill(isPrime, isPrime + MAX_PRIME, true);
  p = 0;
  isPrime[0] = isPrime[1] = false;

  for (int i = 2; i <= MAX_PRIME; i++) {
    if (isPrime[i]) {
      prime[p++] = i;
    } else
      continue;
    // ツづ督づゥツつ「ツづ可つゥツつッツづゥ
    for (int j = 2 * i; j <= MAX_PRIME; j += i) {
      isPrime[j] = false;
    }
    cout << flush;
  }
}

int main() {
  erats();
  vector<int> data(1000100, 0);
  int n;
  while (cin >> n && n != 0) {
    int cnt = 0;
    for (int i = 0; i < p; i++) {
      int left = n - prime[i];
      if (left < 0 || left < (n / 2))
        break;
      if (isPrime[left])
        cnt++;
    }
    cout << cnt << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:


#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>

using namespace std;

#define EPS (1e-10)
#define EQ(a, b) (abs((a) - (b)) < EPS)
#define EQV(a, b) (EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()))

typedef complex<double> P;
typedef long long ll;

const int MAX_SIZE = 10000;
const int MAX_PRIME = 500000;

int prime[MAX_PRIME + 1];
bool isPrime[MAX_PRIME + 1];
int p;

void erats() {
  // primeツδ環スツトツづーツ渉可甘コツ可サ
  fill(isPrime, isPrime + MAX_PRIME, true);
  p = 0;
  isPrime[0] = isPrime[1] = false;

  for (int i = 2; i <= MAX_PRIME; i++) {
    if (isPrime[i]) {
      prime[p++] = i;
    } else
      continue;

    // ツづ督づゥツつ「ツづ可つゥツつッツづゥ
    for (int j = 2 * i; j <= MAX_PRIME; j += i) {
      isPrime[j] = false;
    }
    cout << flush;
  }
}

int main() {
  erats();
  int n;
  //	int data[10000100];
  vector<int> data(1000100, 0);
  for (int i = 0; i < p; i++) {
    // if(prime[i]>(n/2)+1)
    //	break;
    for (int j = i; j < p; j++) {
      data[prime[i] + prime[j]]++;
    }
  }

  while (cin >> n && n != 0) {
    cout << data[n] << endl;
  }

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

#include <algorithm>
#include <bitset>
#include <cfloat>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

void makePrimeNumber(
    int N,
    vector<bool> &
        prime) // 0ツ暗按湘」Nツ暗按可コツづ個青ョツ青板つゥツづァツ素ツ青板づーツ探ツつキ
{
  prime.assign(N + 1, true);
  prime[0] = prime[1] = false;
  for (int i = 2; i * i <= N; i++) {
    if (prime[i]) {
      for (int j = i; i * j <= N; j++) {
        prime[i * j] = false;
      }
    }
  }
}

int main() {
  vector<bool> prime;
  makePrimeNumber(1000000, prime);

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

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

    int ret = 0;
    for (unsigned i = 0; num[i] <= n / 2; ++i) {
      if (prime[n - num[i]])
        ++ret;
    }
    cout << ret << endl;
  }
}

Error: WA

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cfloat>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

void makePrimeNumber(
    int N,
    vector<bool> &
        prime) // 0ツ暗按湘」Nツ暗按可コツづ個青ョツ青板つゥツづァツ素ツ青板づーツ探ツつキ
{
  prime.assign(N + 1, true);
  prime[0] = prime[1] = false;
  for (int i = 2; i * i <= N; i++) {
    if (prime[i]) {
      for (int j = i; i * j <= N; j++) {
        prime[i * j] = false;
      }
    }
  }
}

int main() {
  vector<bool> prime;
  makePrimeNumber(50000, prime);

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

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

    int ret = 0;
    for (unsigned i = 0; num[i] <= n / 2; ++i) {
      if (prime[n - num[i]])
        ++ret;
    }
    cout << ret << endl;
  }
}
Problem p00185 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define REP(i, j) for (int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for (int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;
const int MAX_N = 1000001;

bool isp[MAX_N];

void make_prime() {
  REP(i, MAX_N) isp[i] = true;
  isp[0] = isp[1] = false;
  FOR(i, 2, MAX_N) {
    if (!isp[i])
      continue;
    for (int j = i + i; j < MAX_N; j += i)
      isp[j] = false;
  }
}

int main() {
  make_prime();
  int N;
  while (cin >> N && N) {
    int cnt = 0;
    FOR(i, 2, N / 2) if (isp[i] && isp[N - i])++ cnt;
    if (isp[N / 2])
      ++cnt;
    cout << cnt << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define REP(i, j) for (int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for (int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;
const int MAX_N = 1000001;

vector<int> p;
bool isp[MAX_N];
int ans[MAX_N];

void make_prime() {
  REP(i, MAX_N) isp[i] = true;
  isp[0] = isp[1] = false;
  FOR(i, 2, MAX_N) {
    if (!isp[i])
      continue;
    p.push_back(i);
    for (int j = i + i; j < MAX_N; j += i)
      isp[j] = false;
  }
}

int main() {
  make_prime();
  memset(ans, 0, sizeof(ans));
  REP(i, p.size())
  FOR(j, i, p.size()) if (p[i] + p[j] < MAX_N)++ ans[p[i] + p[j]];
  int N;
  while (cin >> N && N)
    cout << ans[N] << endl;
  return 0;
}
Problem p00185 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstring>
#include <iostream>

using namespace std;

int p[1000000];
int pt[1000000];
int pn;

int dp[1000001];

void init() {
  memset(p, 1, sizeof(int) * 1000000);
  memset(pt, 0, sizeof(int) * 1000000);
  memset(dp, 0, sizeof(int) * 1000001);
  p[0] = p[1] = 0;
  for (int i = 0; i < 1000; i++) {
    if (p[i]) {
      for (int j = i + i; j < 1000000; j += i) {
        p[j] = 0;
      }
    }
  }
  pn = 0;
  for (int i = 0; i < 1000000; i++) {
    if (p[i]) {
      pt[pn] = i;
      pn++;
    }
  }
}

int solve(int t) {
  int res = 0;
  for (int i = 0; pt[i] <= t / 2; i++) {
    if (p[t - pt[i]]) {
      res++;
    }
  }
  return res;
}

int main() {
  int in;
  init();
  while (1) {
    cin >> in;
    if (!in) {
      break;
    }
    cout << solve(in) << endl;
  }
}

Error: TLE

Fixed submission:

#include <cstring>
#include <iostream>

using namespace std;

int p[1000000];
int pt[1000000];
int pn;

int dp[1000001];

void init() {
  memset(p, 1, sizeof(int) * 1000000);
  memset(pt, 0, sizeof(int) * 1000000);
  memset(dp, 0, sizeof(int) * 1000001);
  p[0] = p[1] = 0;
  for (int i = 0; i < 1000; i++) {
    if (p[i]) {
      for (int j = i + i; j < 1000000; j += i) {
        p[j] = 0;
      }
    }
  }
  pn = 0;
  for (int i = 0; i < 1000000; i++) {
    if (p[i]) {
      pt[pn] = i;
      pn++;
    }
  }

  for (int i = 0; i < pn; i++) {
    for (int j = i; j < pn; j++) {
      if (pt[i] + pt[j] > 1000000) {
        break;
      }
      dp[pt[i] + pt[j]]++;
    }
  }
}

int main() {
  int in;
  init();
  while (1) {
    cin >> in;
    if (!in) {
      break;
    }
    cout << dp[in] << endl;
  }
}