alexjercan/bugnet huggingface dataset:
Problem p00054 (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 <stack>
#include <string>
#include <vector>
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> P1;
typedef pair<P, P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
int main() {
  int a, b, c;
  while (scanf("%d %d %d", &a, &b, &c) != EOF) {
    a %= b;
    int ans = 0;
    for (int i = 0; i < c; i++) {
      a *= 10;
      ans += a / b;
      a %= b;
    }
    printf("%d\\n", ans);
  }
}

Error: TLE

Fixed submission:

#include <cmath>
#include <cstdio>
int c;
long double a, b;
int main() {
  while (scanf("%lf %lf %d", &a, &b, &c) != EOF) {
    int ans = 0;
    for (int i = 10; i <= pow(10.0, c); i *= 10) {
      int ryu = a / b * i;
      ans += ryu % 10;
    }
    printf("%d\\n", ans);
  }
}
Problem p00054 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>

int main() {
  int a, b, n;
  while (std::cin >> a >> b >> n) {
    int sum = 0;
    while (n--) {
      a *= 10;
      sum += (a / b) % 10;
      a %= b;
    }

    std::cout << sum << std::endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <string>

using namespace std;

int main() {
  int a, b, n;
  while (cin >> a >> b >> n) {
    int div_int = a / b;
    double div = static_cast<double>(a) / b;
    div -= div_int;

    char str_ch[20];
    sprintf(str_ch, "%.9f", div);
    string str = str_ch;
    str = str.substr(2);

    int sum = 0;
    for (auto i = 0; i < n; i++) {
      sum += str.at(i) - '0';
    }

    cout << sum << endl;
  }

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

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

int main() {
  int a;
  while (cin >> a) {
    int b, n;
    int sum = 0;
    cin >> b >> n;
    //    cout << a << " " << b << " " << sum << endl;
    a %= b;
    a *= 10;
    for (int i = 0; a > 0 && i < n; i++) {
      sum += a / b;
      //      cout << a << " " << b << " " << sum << endl;
      a %= b;
      a *= 10;
    }
    cout << sum << endl;
  }
  return EXIT_SUCCESS;
}

Error: 0

Fixed submission:

#include <climits>
#include <cstdlib>
#include <deque>
#include <iostream>
using namespace std;

int get_sum(deque<int> &q, int sp, int ep) { return (q[ep + 1] - q[sp]); }

int main() {
  int a, b, n;
  while (cin >> a) {
    cin >> b >> n;
    int i, q;
    int sp = INT_MAX, ep = INT_MAX;
    deque<int> qqq;
    deque<int> rem;
    a %= b;
    a *= 10;

    for (i = 0; a > 0; a *= 10, i++) {
      q = a / b;
      a %= b;
      rem.push_back(a);
      qqq.push_back(q);
      //      cout << i << " " << q << " " << a << endl;
      for (int j = 0; j < i; j++) {
        if (rem[j] == a) {
          sp = j + 1;
          ep = i - 1;
        }
      }
      if (sp != INT_MAX) {
        break;
      }
    }

    int sum_before_loop = 0;
    // to get sum x to y
    // [y + 1] - [x]
    deque<int> sums_in_loop;
    sums_in_loop.push_back(0);
    for (int j = 0; j <= i; j++) {
      if (j < sp) {
        sum_before_loop += qqq[j];
      } else {
        sums_in_loop.push_back(sums_in_loop.back() + qqq[j]);
      }
    }

    int ans = 0;
    if (i == 0) {
      ans = 0;
    } else if (sp == INT_MAX) {
      ans = sum_before_loop;
    } else if (ep - sp == -1) {
      ans = sum_before_loop + sums_in_loop.back() * (n - sp);
    } else {
      int loop_num = (n - sp) / (ep - sp + 1);
      int loop_rem = (n - sp) % (ep - sp + 1);
      //     cout << loop_num << " " << loop_rem << " " << sums_in_loop.back()
      //     << endl; cout << sum_before_loop << " " << sums_in_loop.back() << "
      //     " << loop_rem << " " << loop_num << endl;
      ans = sum_before_loop + sums_in_loop.back() * loop_num;
      ans += sums_in_loop[loop_rem - 1];
      // sp = 2  ep = 4 n = 9
      // 0 1 (2 3 4) (5 6 7) 8| 9 10
    }
    cout << ans << endl;
  }
  return EXIT_SUCCESS;
}
Problem p00054 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#pragma comment(linker, "/STACK:400000000")

#define EPS 1e-9
#define INF MOD
#define MOD 1000000007LL
#define fir first
#define foreach(it, X) for (it = X.begin(); it != X.end(); it++)
#define iss istringstream
#define ite iterator
#define ll long long
#define mp make_pair
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < n; i++)
#define pi pair<int, int>
#define pb push_back
#define sec second
#define sh(i) (1LL << i)
#define sst stringstream
#define sz size()
#define vi vector<int>
#define vc vector
#define vl vector<ll>
#define vs vector<string>

int a, b, n; // n<=10^6

int main() {
  while (cin >> a >> b >> n) {
    a %= b;
    int ans = 0;
    rep(i, n) {
      int x = a * 10 / b;
      ans += x;
      a = a * 10 - x * b;
    }
    cout << ans << endl;
  }
}

Error: WA

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#pragma comment(linker, "/STACK:400000000")

#define EPS 1e-9
#define INF MOD
#define MOD 1000000007LL
#define fir first
#define foreach(it, X) for (it = X.begin(); it != X.end(); it++)
#define iss istringstream
#define ite iterator
#define ll long long
#define mp make_pair
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < n; i++)
#define pi pair<int, int>
#define pb push_back
#define sec second
#define sh(i) (1LL << i)
#define sst stringstream
#define sz size()
#define vi vector<int>
#define vc vector
#define vl vector<ll>
#define vs vector<string>

int a, b, n;

int main() {
  while (cin >> a >> b >> n) {
    if (n > 10)
      return -1;
  }
}
Problem p00055 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define fi first
#define se second
#define fcout(n) cout << fixed << setprecision((n))
using namespace std;
bool value(int y, int x, int R, int C) {
  return 0 <= y && y < R && 0 <= x && x < C;
}
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<vi> vvi;
double pie = acos(-1);
int INF = 10000009;
int dx[4] = {0, -1, 0, 1};
int dy[4] = {-1, 0, 1, 0};
int main() {
  long double a, s[15], sum = 0;
  while (true) {
    cin >> a;
    if (cin.eof())
      break;
    s[0] = a;
    for (int i = 1; i < 10; i++) {
      if (i % 2 != 0) {
        s[i] = 2.0 * s[i - 1];
      } else {
        s[i] = s[i - 1] / 3.0;
      }
    }
    for (int i = 0; i < 10; i++) {
      sum += s[i];
    }
    fcout(8) << sum << endl;
    sum = 0;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define fi first
#define se second
#define fcout(n) cout << fixed << setprecision((n))
using namespace std;
bool value(int y, int x, int R, int C) {
  return 0 <= y && y < R && 0 <= x && x < C;
}
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<vi> vvi;
double pie = acos(-1);
int INF = 10000009;
int dx[4] = {0, -1, 0, 1};
int dy[4] = {-1, 0, 1, 0};
int main() {
  long double a, s[15], sum = 0;
  while (true) {
    cin >> a;
    s[0] = a;
    for (int i = 1; i < 10; i++) {
      if (i % 2 != 0) {
        s[i] = 2.00000000000 * s[i - 1];
      } else {
        s[i] = s[i - 1] / 3.000000000;
      }
    }
    for (int i = 0; i < 10; i++) {
      sum += s[i];
    }
    fcout(8) << sum << endl;
    sum = 0;
  }
}
Problem p00055 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iomanip>
#include <iostream>
int main() {
  while (true) {
    double a;
    std::cin >> a;
    if (std::cin.eof()) {
      break;
    }
    std::cout << std::fixed << std::setprecision(10) << a * 211 / 27
              << std::endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <iomanip>
#include <iostream>
int main() {
  while (true) {
    double a;
    std::cin >> a;
    std::cout << std::fixed << std::setprecision(10) << a * 211 / 27
              << std::endl;
  }
  return 0;
}
Problem p00055 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <ctype.h>
#include <functional>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <queue>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main() {
  long double a, b, sum;
  while (cin >> a) {
    sum = a;
    for (int i = 0; i < 9; i++) {
      if (i % 2 == 0) {
        b = a * 2;
        sum = sum + b;
      } else {
        b = a / 3;
        sum = sum + b;
      }
      a = b;
    }
    cout << fixed << setprecision(8) << sum << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <ctype.h>
#include <functional>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <queue>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main() {
  long double a, b, sum;
  while (1) {
    cin >> a;
    sum = a;
    for (int i = 0; i < 9; i++) {
      if (i % 2 == 0) {
        b = a * 2;
        sum = sum + b;
      } else {
        b = a / 3;
        sum = sum + b;
      }
      a = b;
    }
    cout << fixed << setprecision(8) << sum << endl;
  }

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

#include <stdio.h>

int main(void) {

  double a[10];
  double s;
  int i;

  while (scanf("%lf", &a[0]) != EOF) {

    for (i = 0; i < 4; i++) {

      a[2 * i + 1] = 2.0 * a[2 * i];
      a[2 * i + 2] = a[2 * i + 1] / 3.0;
    }

    a[9] = 2.0 * a[8];

    s = 0.0;

    for (i = 0; i < 10; i++) {

      s += a[i];
    }

    printf("%.8lf\\n", s);
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>

int main(void) {

  double a[10];
  double s;
  int i;
  while (1) {
    scanf("%lf", &a[0]);

    for (i = 0; i < 4; i++) {

      a[2 * i + 1] = 2.0 * a[2 * i];
      a[2 * i + 2] = a[2 * i + 1] / 3.0;
    }

    a[9] = 2.0 * a[8];

    s = 0.0;

    for (i = 0; i < 10; i++) {

      s += a[i];
    }

    printf("%.8lf\\n", s);
  }
  return 0;
}
Problem p00055 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <stdio.h>
using namespace std;

int main() {
  double a;
  while (1) {
    cin >> a;
    if (cin.eof())
      break;
    printf("%.8f\\n", 211.0 / 27.0 * a);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <stdio.h>
using namespace std;

int main() {
  double a;
  while (1) {
    cin >> a;
    printf("%.8f\\n", 211.0 / 27.0 * a);
  }
  return 0;
}
Problem p00055 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
int main(void) {

  double a;

  while (cin >> a) {
    double ans = 0;
    ans += a;
    for (int i = 2; i <= 10; i++) {
      if (i % 2 == 0)
        a *= 2;
      else
        a /= 3;
      ans += a;
    }
    printf("%lf\\n", ans);
  }
  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
int main(void) {

  double a;

  while (cin >> a) {
    double ans = 0;
    ans += a;
    for (int i = 2; i <= 10; i++) {
      if (i % 2 == 0)
        a *= 2;
      else
        a /= 3;
      ans += a;
    }
    printf("%llf\\n", ans);
  }
  return 0;
}
Problem p00055 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <functional>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;

long double a = 0;

int main() {

  while (cin >> a) {

    long double s = 0;

    s = a;
    for (int i = 0; i < 4; i++) {
      a = 2 * a;
      s = s + a;
      a = a / 3;
      s = s + a;
    }
    s = s + a * 2;
    cout << setprecision(10) << s << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <functional>
#include <iostream>
#include <math.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;

int main() {
  while (true) {
    double a = 0;
    double s = 0;
    cin >> a;
    s = a;
    for (int i = 0; i < 4; i++) {
      a = 2 * a;
      s = s + a;
      a = a / 3;
      s = s + a;
    }
    s = s + a * 2;
    cout << s << endl;
  }
  return 0;
}
Problem p00055 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  double d[10];
  double a;
  while (cin >> a) {
    d[0] = a;
    d[1] = d[0] * 2;
    d[2] = d[1] / 3;
    d[3] = d[2] * 2;
    d[4] = d[3] / 3;
    d[5] = d[4] * 2;
    d[6] = d[5] / 3;
    d[7] = d[6] * 2;
    d[8] = d[7] / 3;
    d[9] = d[8] * 2;
    double ca = 0;
    for (int i = 0; i < 10; i++) {
      ca += d[i];
    }
    cout << fixed << setprecision(9) << ca << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  double d[10];
  double a;
  while (cin >> a) {
    d[0] = a;
    d[1] = d[0] * 2;
    for (int i = 2; i < 10; i + 2) {
      d[i] = d[i - 1] / 3;
      d[i + 1] = d[i] * 2;
    }
    int ca = 0;
    for (int i = 0; i < 10; i++) {
      ca += d[i];
    }
    cout << fixed << setprecision(9) << ca << endl;
  }
  return 0;
}
Problem p00055 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
using namespace std;

int main() {
  double a;
  while (scanf("%lf", &a) == 1) {
    double S = a;
    for (int i = 2; i <= 10; i++) {
      if (i % 2)
        a /= 3.0;
      else
        a *= 2.0;
      S += a;
    }
    printf("%.8f\\n", S);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
using namespace std;

int main() {
  double a, S = 0.0;
  while (scanf("%lf", &a)) {
    S += a;
    for (int i = 2; i <= 10; i++) {
      if (i % 2)
        a /= 3.0;
      else
        a *= 2.0;
      S += a;
    }
    printf("%.8f\\n", S);
  }
  return 0;
}
Problem p00055 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define all(vec) vec.begin(), vec.end()
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD = 1000000007;
const ll INF = 1000000010;
const ll LINF = 4000000000000000010LL;
const int MAX = 310;
const double EPS = 1e-9;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
int main() {
  double b;
  while (cin >> b) {
    double a[11];
    a[1] = b;
    double sum = b;
    for (int i = 2; i <= 10; i++) {
      if (i % 2) {
        a[i] = a[i - 1] / 3;
      } else {
        a[i] = a[i - 1] * 2;
      }
      sum += a[i];
    }
    printf("%.9lf\\n", sum);
  }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define all(vec) vec.begin(), vec.end()
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD = 1000000007;
const ll INF = 1000000010;
const ll LINF = 4000000000000000010LL;
const int MAX = 310;
const double EPS = 1e-9;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
int main() {
  double b;
  while (cin >> b, b) {
    double a[11];
    a[1] = b;
    double sum = b;
    for (int i = 2; i <= 10; i++) {
      if (i % 2) {
        a[i] = a[i - 1] / 3;
      } else {
        a[i] = a[i - 1] * 2;
      }
      sum += a[i];
    }
    printf("%.9lf\\n", sum);
  }
}
Problem p00055 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>

using namespace std;

double num(double);

int main(void) {
  double a, sum;

  while ((scanf("%lf", &a)) != EOF) {
    sum = num(a);
    printf("%.6f\\n", sum);
  }

  return 0;
}

double num(double x) {
  int i;
  double data[11], sum = 0;

  data[1] = x;
  for (i = 2; i <= 10; i++) {
    if (i % 2 == 0) {
      data[i] = data[i - 1] * 2;
    } else {
      data[i] = data[i - 1] / 3;
    }
  }
  for (i = 1; i <= 10; i++) {
    sum += data[i];
  }

  return sum;
}

Error: TLE

Fixed submission:

#include <cstdio>

using namespace std;

double num(double);

int main(void) {
  double a, sum;

  while ((scanf("%lf", &a)) != 0) {
    sum = num(a);
    printf("%.5f\\n", sum);
  }

  return 0;
}

double num(double x) {
  int i;
  double data[11], sum = 0;

  data[1] = x;
  for (i = 2; i <= 10; i++) {
    if (i % 2 == 0) {
      data[i] = data[i - 1] * 2;
    } else {
      data[i] = data[i - 1] / 3;
    }
  }
  for (i = 1; i <= 10; i++) {
    sum += data[i];
  }

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

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

bool is_prime[200000];
int cnt[50001];
vector<int> primes;

void calc_prime(int n) {
  for (int i = 0; i <= n; ++i)
    is_prime[i] = true;
  is_prime[0] = is_prime[1] = false;
  for (int i = 2; i <= n; ++i) {
    if (is_prime[i]) {
      primes.push_back(i);
      for (int j = i * 2; j <= n; j += i)
        is_prime[j] = false;
    }
  }
}

int main() {
  calc_prime(50000);
  for (int i = 0; i < primes.size(); ++i) {
    for (int j = i; j < primes.size(); ++j) {
      if (primes[i] + primes[j] > 50000)
        break;
      cnt[primes[i] + primes[j]]++;
    }
  }
  int n;
  while (cin >> n && n) {
    cout << cnt[n] << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

bool is_prime[200000];
vector<int> primes;

void calc_prime(int n) {
  for (int i = 0; i <= n; ++i)
    is_prime[i] = true;
  is_prime[0] = is_prime[1] = false;
  for (int i = 2; i <= n; ++i) {
    if (is_prime[i]) {
      primes.push_back(i);
      for (int j = i * 2; j <= n; j += i)
        is_prime[j] = false;
    }
  }
}

int main() {
  calc_prime(50000);
  int n;
  while (cin >> n && n) {
    int ans = 0;
    for (int i = 0; i < primes.size(); ++i) {
      for (int j = i; j < primes.size(); ++j) {
        if (primes[i] + primes[j] > n)
          break;
        if (primes[i] + primes[j] == n)
          ans++;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p00056 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main() {
  bool is_prime[100000];
  is_prime[0] = is_prime[1] = false;
  for (int i = 2; i < 100000; i++)
    is_prime[i] = true;
  for (int i = 2; i * i < 100000; i++) {
    if (is_prime[i]) {
      for (int j = i * i; j < 100000; j += i) {
        is_prime[j] = false;
      }
    }
  }
  while (true) {
    int count = 0;
    int n;
    cin >> n;
    if (n == 0) {
      break;
    } else {
      for (int i = 2; i < n / 2 + 1; i++) {
        if (is_prime[i] && is_prime[n - i])
          count++;
      }
      cout << count << endl;
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;

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


#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <vector>
using namespace std;

int main() {
  int n, x, m;
  x = 0;
  m = 0;
  vector<int> v;
  scanf("%d", &n);
  while (n) {
    v.push_back(n);
    if (n > x) {
      x = n;
    }
    scanf("%d", &n);
    m++;
  }
  vector<int> res;
  vector<int> p(x + 1, 1);
  p[0] = 0;
  p[1] = 0;
  for (int t = 2; t <= x; t++) {
    if (p[t] == 0)
      continue;
    // p の倍数を全て消す。
    for (int k = t * 2; k <= x; k += t) {
      p[k] = 0;
    }
    res.push_back(t);
  }
  int a = 0;
  int s;
  for (int t = 0; t < m; t++) {
    a = 0;
    s = res.size();
    for (int k = 0; k < s; k++) {
      if (v[t] - res[k] >= 1) {
        if (p[v[t] - res[k]] == 1) {
          a++;
        }
      }
    }
    a = a / 2 + a % 2;
    printf("%d\\n", a);
  }
}


Error: 0

Fixed submission:


#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <vector>
using namespace std;

int main() {
  int n, x, m;
  x = 0;
  m = 0;
  vector<int> v;
  scanf("%d", &n);
  while (n) {
    v.push_back(n);
    if (n > x) {
      x = n;
    }
    scanf("%d", &n);
    m++;
  }
  vector<int> res;
  vector<int> p(x + 1, 1);
  p[0] = 0;
  p[1] = 0;
  for (int t = 2; t <= x; t++) {
    if (p[t] == 0)
      continue;
    // p の倍数を全て消す。
    for (int k = t * 2; k <= x; k += t) {
      p[k] = 0;
    }
    res.push_back(t);
  }
  int a = 0;
  int s;
  for (int t = 0; t < m; t++) {
    a = 0;
    s = res.size();
    for (int k = 0; k < s; k++) {
      if (p[v[t] - res[k]] == 1) {
        a++;
      }
    }
    a = a / 2 + a % 2;
    printf("%d\\n", a);
  }
}
Problem p00056 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

bool p[50050];

void erato() {
  fill(p, p + 50050, true);
  p[0] = p[1] = false;

  for (int i = 0; i * i < 50050; i++) {
    if (!p[i])
      continue;
    for (int j = i + i; j < 50050; j += i) {
      p[j] = false;
    }
  }
}

int main() {
  erato();
  int input;
  int ans;
  while (cin >> input, input) {
    ans = 0;
    for (int i = 0; i <= input / 2; i++) {
      if (p[i] && p[input - i]) {
        if (i + input - i == input)
          ans++;
      }
    }

    cout << ans << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

bool p[50050];

void erato() {
  fill(p, p + 50050, true);
  p[0] = p[1] = false;

  for (int i = 0; i * i < 50050; i++) {
    if (!p[i])
      continue;
    for (int j = i + i; j < 50050; j += i) {
      p[j] = false;
    }
  }
}

int main() {
  erato();
  int input;
  int ans;
  while (cin >> input, input) {
    ans = 0;
    if (p[input]) {
      cout << 0 << endl;
      continue;
    }

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

    cout << ans << endl;
  }
}