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

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

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

int main(void) {
  int n;
  while (scanf("%d", &n), n) {

    for (int i = n; 5 <= i; i--) {
      // cout << i << endl;
      if (isPrime(i) && isPrime(i - 2)) {
        cout << i - 2 << " " << i << endl;
        break;
      }
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

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

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

int main(void) {
  int n;
  while (scanf("%d", &n), n) {

    for (int i = n; 5 <= i; i--) {
      // cout << i << endl;
      if (isPrime(i) && isPrime(i - 2)) {
        cout << i - 2 << " " << i << endl;
        break;
      }
    }
  }

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

#include <stdio.h>

int isprime(int n) {
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0)
      return 0;
  }
  return 1;
}

int main() {
  int k, v, a = 0, b = 0;
  while (1) {
    scanf("%d", &v);
    if (v == 0)
      break;
    for (k = v; k > 0; k--) {
      if (isprime(k) == 1 && isprime(k - 2) == 1) {
        a = k - 2;
        b = k;
        break;
      }
    }
    printf("%d %d\\n", a, b);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>

int isprime(int n) {
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0)
      return 0;
  }
  return 1;
}

int main() {
  int k, v, a = 0, b = 0;
  while (1) {
    scanf("%d", &v);
    if (v == 0)
      break;
    for (k = 1; k <= v; k++) {
      if (isprime(k) == 1 && isprime(k - 2) == 1) {
        a = k - 2;
        b = k;
      }
    }
    printf("%d %d\\n", a, b);
  }
}
Problem p00150 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>

#define MYSCAN scanf

int main(void) {
  int n, p;
  int flag;
  int i, j;
  int tmp;

  while (1) {
    MYSCAN("%d", &n);
    if (n == 0) {
      break;
    }

    p = 0;
    if (n % 2 == 0) {
      n--;
    }
    for (i = n; i > 2; i -= 2) {
      flag = 1;
      tmp = i / 2;
      // iテ」ツ?古ァツエツ?ヲツ閉ーテ」ツ?凝」ツ?ゥテ」ツ??」ツ?凝」ツδ?」ツつァテ」ツδε」ツつッ
      for (j = 3; j < tmp; j += 2) {
        if (i % j == 0) {
          flag = 0;
          break;
        }
      }

      // iテ」ツ?古ァツエツ?ヲツ閉ーテ」ツ??」ツ?」テ」ツ?淌」ツつ?
      if (flag == 1) {
        // テ・ツ??」ツつ暗」ツつ?テ」ツ?、テ・ツケツエテ、ツクツ凝」ツ??」ツ?」テ」ツ?淌」ツつ嘉・ツ?コテ・ツ環?
        if (i == p - 2) {
          printf("%d %d\\n", i, p);
          break;
        }
        // テ」ツ?敕」ツ??」ツ?佚」ツつε」ツ?ェテ」ツ?凝」ツ?」テ」ツ?淌」ツつ嘉ィツ?ェテ・ツ按?」ツ?古・ツ??」ツ?ォテ」ツ?ェテ」ツつ?
        p = i;
      }
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>

#define MYSCAN scanf

int main(void) {
  int n, p;
  int flag;
  int i, j;
  int tmp;

  while (1) {
    MYSCAN("%d", &n);
    if (n == 0) {
      break;
    }

    p = 0;
    if (n % 2 == 0) {
      n--;
    }
    for (i = n; i > 1; i -= 2) {
      flag = 1;
      // iテ」ツ?古ァツエツ?ヲツ閉ーテ」ツ?凝」ツ?ゥテ」ツ??」ツ?凝」ツδ?」ツつァテ」ツδε」ツつッ
      for (j = i / 2; j > 1; j--) {
        if (i % j == 0) {
          flag = 0;
          break;
        }
      }

      // iテ」ツ?古ァツエツ?ヲツ閉ーテ」ツ??」ツ?」テ」ツ?淌」ツつ?
      if (flag == 1) {
        // テ・ツ??」ツつ暗」ツつ?テ」ツ?、テ・ツケツエテ、ツクツ凝」ツ??」ツ?」テ」ツ?淌」ツつ嘉・ツ?コテ・ツ環?
        if (i == p - 2) {
          printf("%d %d\\n", i, p);
          break;
        }
        // テ」ツ?敕」ツ??」ツ?佚」ツつε」ツ?ェテ」ツ?凝」ツ?」テ」ツ?淌」ツつ嘉ィツ?ェテ・ツ按?」ツ?古・ツ??」ツ?ォテ」ツ?ェテ」ツつ?
        p = i;
      }
    }
  }

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

#include <cmath>
#include <cstring>
#include <iostream>
#include <ostream>
#include <vector>

using std::cerr;
using std::cin;
using std::cout;
using std::endl;

template <typename T>
std::ostream &operator<<(std::ostream &os, std::vector<T> v) {
  os << "[";
  for (int i = 0; i < int(v.size()); i++) {
    os << v[i] << (i == int(v.size()) - 1 ? "" : ", ");
  }
  os << "]";
  return os;
}

// n 以下の素数のリストを返す O(nlog(log(n)))
std::vector<int> eratosthenes(int n) {
  std::vector<int> is_prime(n + 1, 1);
  std::vector<int> primes;

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

  return primes;
}

int main() {
  int n;

  while (cin >> n, n) {
    std::vector<int> primes = eratosthenes(n);

    for (int i = int(primes.size()) - 1; i > 0; i--) {
      if (primes[i] - primes[i - 1] == 2) {
        cout << primes[i - 1] << " " << primes[i] << endl;
        break;
      }
    }
  }

  return 0;
}


Error: -11

Fixed submission:

#include <cstring>
#include <functional>
#include <iostream>
#include <string>

using std::cerr;
using std::cin;
using std::cout;
using std::endl;

const int vx[4] = {0, 1, 0, -1}, vy[4] = {1, 0, -1, 0};

int solve(int H, int W, std::string s[]) {
  int ret = 0;
  int sx, sy;
  bool is_searched[21][21];

  std::memset(is_searched, false, sizeof is_searched);

  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      if (s[i][j] == '@') {
        sx = i, sy = j;
        break;
      }
    }
  }

  std::function<int(int, int)> dfs = [&](int x, int y) {
    int res = 0;
    is_searched[x][y] = true;

    for (int i = 0; i < 4; ++i) {
      int nx = x + vx[i], ny = y + vy[i];

      if (0 <= nx && nx < H && 0 <= ny && ny < W && !is_searched[nx][ny] &&
          s[nx][ny] == '.') {

        res += dfs(nx, ny) + 1;
      }
    }

    return res;
  };

  ret = dfs(sx, sy) + 1; // +1 は'@' の分

  return ret;
}

int main() {
  int W, H;
  std::string s[21];

  while (cin >> W >> H, W | H) {
    for (int i = 0; i < H; ++i) {
      cin >> s[i];
    }

    int ans = solve(H, W, s);

    cout << ans << endl;
  }

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

#include <stdio.h>

int isprime(int n) {
  int i;
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0)
      return 0;
  }
  return 1;
}

int main() {
  int i, k, v, an1, an2, suu;
  int MAX_V = 10000;
  int prime[MAX_V + 1];
  for (i = 0; i <= MAX_V; i++) {
    prime[i] = 1;
  }
  for (i = 2; i * i <= MAX_V; i++) {
    if (prime[i]) {
      for (k = 2 * i; k <= MAX_V; k += i) {
        prime[k] = 0;
      }
    }
  }
  while (1) {
    scanf("%d", &suu);
    if (suu != 0) {
      for (k = 2; k <= suu; k++) {
        if (prime[k - 2] == 1 && prime[k] == 1) {
          an1 = k - 2;
          an2 = k;
        }
      }
      printf("%d %d\\n", an1, an2);
    } else {
      break;
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>

int isprime(int n) {
  int i;
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0)
      return 0;
  }
  return 1;
}

int main() {
  int k, g, j, suu, an1, an2;
  int su[10000] = {1};
  for (k = 0; k < 10000; k++) {
    if (isprime(k) == 1) {
      j = 0;
      for (g = 2; j <= 10000; g++) {
        j = g * k;
        su[j] = 0;
      }
    }
  }
  while (1) {
    scanf("%d", &suu);
    if (suu != 0) {
      for (k = 2; k <= suu; k++) {
        if (su[k - 2] == 1 && su[k] == 1) {
          an1 = k - 2;
          an2 = k;
        }
      }
      printf("%d %d\\n", an1, an2);
    } else {
      break;
    }
  }
  return 0;
}
Problem p00150 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>

int main() {
  int i, k, v, an1, an2, suu;
  int MAX_V = 10000;
  int prime[MAX_V + 1];
  for (i = 0; i <= MAX_V; i++) {
    prime[i] = 1;
  }
  for (i = 2; i * i <= MAX_V; i++) {
    if (prime[i]) {
      for (k = 2 * i; k <= MAX_V; k += i) {
        prime[k] = 0;
      }
    }
  }
  while (1) {
    scanf("%d", &suu);
    if (suu != 0) {
      for (k = 2; k <= suu; k++) {
        if (prime[k - 2] == 1 && prime[k] == 1) {
          an1 = k - 2;
          an2 = k;
        }
      }
      printf("%d %d\\n", an1, an2);
    } else {
      break;
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>

int isprime(int n) {
  int i;
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0)
      return 0;
  }
  return 1;
}

int main() {
  int k, suu, an1, an2;
  while (1) {
    scanf("%d", &suu);
    if (suu != 0) {
      for (k = 2; k <= suu; k++) {
        if (isprime(k - 2) == 1 && isprime(k) == 1) {
          an1 = k - 2;
          an2 = k;
        }
      }
      printf("%d %d\\n", an1, an2);
    } else {
      break;
    }
  }
}
Problem p00150 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>

int main() {
  int i, k, v, an1, an2, suu;
  int MAX_V = 1000000;
  int prime[MAX_V + 1];
  for (i = 2; i <= MAX_V; i++) {
    prime[i] = 1;
  }
  for (i = 2; i * i <= MAX_V; i++) {
    if (prime[i]) {
      for (k = 2 * i; k <= MAX_V; k += i) {
        prime[k] = 0;
      }
    }
  }
  while (1) {
    scanf("%d", &suu);
    if (suu == 0)
      break;
    for (k = 2; k <= suu; k++) {
      if (prime[k - 2] == 1 && prime[k] == 1) {
        an1 = k - 2;
        an2 = k;
      }
    }
    printf("%d %d\\n", an1, an2);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>

int isprime(int n) {
  int i;
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0)
      return 0;
  }
  return 1;
}

int main() {
  int k, suu, an1, an2;
  while (1) {
    scanf("%d", &suu);
    if (suu != 0) {
      for (k = 2; k <= suu; k++) {
        if (isprime(k - 2) == 1 && isprime(k) == 1) {
          an1 = k - 2;
          an2 = k;
        }
      }
      printf("%d %d\\n", an1, an2);
    } else {
      break;
    }
  }
}
Problem p00150 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>
const int MAX_V = 10000;
int prime[MAX_V + 1];
int main() {
  int i, k, n, v;
  for (i = 2; i <= MAX_V; i++) {
    prime[i] = 1;
  }
  for (i = 2; i * i <= MAX_V; i++) {
    if (prime[i]) {
      for (k = 2 * i; k <= MAX_V; k += i) {
        prime[k] = 0;
      }
    }
  }
  while (1) {
    scanf("%d", &n);
    if (n == 0)
      break;
    for (v = n - 2; v >= 2; v--) {
      int isprime = prime[v] * prime[v + 2];
      if (isprime) {
        printf("%d %d\\n", v, v + 2);
        break;
      }
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>
int isprime(int n) {
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0)
      return 0;
  }
  return 1;
}
int main() {
  int k, n;
  while (1) {
    scanf("%d", &n);
    if (n == 0)
      break;
    for (k = n - 2; k >= 2; k--) {
      if (isprime(k) && isprime(k + 2)) {
        printf("%d %d\\n", k, k + 2);
      }
    }
  }
  return 0;
}
Problem p00150 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>
const int MAX_V = 10000;
int prime[MAX_V + 1];
int main() {
  int i, k, n, p, q, v;
  for (i = 2; i <= MAX_V; i++) {
    prime[i] = 1;
  }
  for (i = 2; i * i <= MAX_V; i++) {
    if (prime[i]) {
      for (k = 2 * i; k <= MAX_V; k += i) {
        prime[k] = 0;
      }
    }
  }
  while (1) {
    scanf("%d", &n);
    if (n == 0)
      break;
    for (v = 2; v <= n - 2; v++) {
      int isprime = prime[v] * prime[v + 2];
      if (isprime)
        p = v, q = v + 2;
    }
    printf("%d %d\\n", p, q);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>
int isprime(int n) {
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0)
      return 0;
  }
  return 1;
}
int main() {
  int k, n, p, q;
  while (1) {
    scanf("%d", &n);
    if (n == 0)
      break;
    for (k = 2; k <= n - 2; k++) {
      if (isprime(k) && isprime(k + 2)) {
        p = k;
        q = k + 2;
      }
    }
    printf("%d %d\\n", p, q);
  }
  return 0;
}
Problem p00150 (C++) — buggy submission, verdict: Runtime Error

#include <math.h>
#include <stdio.h>
#include <string.h>
int main(void) {
  int a, s[10001], d, f, g, h, i, j;
  for (i = 2; i <= 10000; i++)
    s[i] = 1;
  s[1] = 0;
  for (i = 2; i <= 10000; i++) {
    if (s[i] == 1) {
      for (j = 2; j <= 5000; j++) {
        if (i * j <= 10000)
          s[i * j] = 0;
      }
    }
  }
  while (1) {
    d = 0;
    f = 0;
    scanf("%d", &a);
    if (a == 0)
      break;
    for (i = a; i > 0; i--) {
      if (s[i] == 1) {
        if (d == 0)
          d = i;
        else
          f = i;
      }
      if (d != 0 && f != 0) {
        if (d - f == 2)
          break;
        d = f;
      }
    }
    printf("%d %d\\n", f, d);
  }
  return 0;
}

Error: 0

Fixed submission:

#include <math.h>
#include <stdio.h>
#include <string.h>
int main(void) {
  int a, s[100000], d, f, g, h, i, j;
  while (1) {
    d = 0;
    f = 0;
    scanf("%d", &a);
    if (a == 0)
      break;
    for (i = 2; i <= a; i++)
      s[i] = 1;
    s[1] = 0;

    for (i = 2; i <= a; i++) {
      if (s[i] == 1) {
        for (j = 2; j <= a / 2; j++)
          s[i * j] = 0;
      }
    }
    for (i = a; i > 0; i--) {
      if (s[i] == 1) {
        if (d == 0)
          d = i;
        else
          f = i;
      }
      if (d != 0 && f != 0) {
        if (d - f == 2)
          break;
        d = f;
      }
    }
    printf("%d %d\\n", f, d);
  }
  return 0;
}
Problem p00150 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>

const int MAX_V = 1000000;
int prime[MAX_V + 1];
int main() {
  int i, k, n, j, p1, q1;
  for (i = 2; i <= MAX_V; i++) {
    prime[i] = 1;
  }
  for (i = 2; i * i <= MAX_V; i++) {
    if (prime[i]) {
      for (k = 2 * i; k <= MAX_V; k += i) {
        prime[k] = 0;
      }
    }
  }
  for (;;) {
    scanf("%d", &n);
    if (n == 0)
      break;
    for (j = 2; j <= n; j++) {
      int isprime = prime[j];
      int isprimee = prime[j - 2];
      if (isprime == 1 && isprimee == 1) {
        q1 = j;
        p1 = q1 - 2;
      }
    }
    printf("%d %d\\n", p1, q1);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>

int isprime(int n) {
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0)
      return 0;
  }
  return 1;
}

int main() {
  int n, i, p1, q1, result, resultt;
  for (;;) {
    scanf("%d", &n);
    if (n == 0)
      break;
    for (i = 2; i <= n; i++) {
      result = isprime(i);
      resultt = isprime(i - 2);
      if (result == 1 && resultt == 1) {
        q1 = i;
        p1 = q1 - 2;
      }
    }
    printf("%d %d\\n", p1, q1);
  }
  return 0;
}
Problem p00150 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>
int main() {
  int i, k, x, a, b, data[10000];
  for (i = 2; i <= 10000; i++) {
    data[i] = 1;
  }
  for (i = 2; i * i <= 10000; i++) {
    if (data[i]) {
      for (k = 2 * i; k <= 10000; k += i) {
        data[k] = 0;
      }
    }
  }
  while (1) {
    a = 0;
    b = 0;
    scanf("%d", &x);
    if (x == 0)
      break;
    for (x; x >= 2; x--) {
      if (data[x] == 1) {
        b = a;
        a = x;
      }
      if (b - a == 2)
        break;
    }
    printf("%d %d\\n", a, b);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>
int main(void) {
  int a, i, flg1, p, q, l, b, a2, b2, n[10000], m[10000], k = 0;
  scanf("%d", &a);
  while (a != 0) {
    flg1 = 1;
    p = 0;
    q = 0;
    a2 = 0;
    b2 = 0;
    for (i = 2; i <= a; i++) {
      for (l = 2; l < i - 2; l++) {
        b = i % l;
        if (b == 0) {
          flg1 = 0;
          break;
        }
      }
      if (flg1 == 1) {
        if (p == 0) {
          q = i;
        } else if (p != 0) {
          q = i;
        }
        if (q - 2 == p) {
          a2 = p;
          b2 = q;
        } else {
          p = q;
        }
      }
      flg1 = 1;
      if (a == 5 || a == 6)
        a2 = 3, b2 = 5;
    }
    n[k] = a2, m[k] = b2;
    k++;
    scanf("%d", &a);
  }
  for (i = 0; i < k; i++)
    printf("%d %d\\n", n[i], m[i]);
  return 0;
}
Problem p00150 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>

int isprime(int n) {
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0)
      return 0;
  }
  return 1;
}

int main() {
  int n, i, p1, q1, result, resultt;
  for (;;) {
    scanf("%d", &n);
    if (n == 0)
      break;
    for (i = n; i >= 0; i--) {
      result = isprime(i);
      resultt = isprime(i - 2);
      if (result == 1 && resultt == 1) {
        q1 = i;
        p1 = q1 - 2;
        break;
      }
    }
    printf("%d %d\\n", p1, q1);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>

int isprime(int n) {
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0)
      return 0;
  }
  return 1;
}

int main() {
  int n, i, p1, q1, result, resultt;
  for (;;) {
    scanf("%d", &n);
    if (n == 0)
      break;
    for (i = 2; i <= n; i++) {
      result = isprime(i);
      resultt = isprime(i - 2);
      if (result == 1 && resultt == 1) {
        q1 = i;
        p1 = q1 - 2;
      }
    }
    printf("%d %d\\n", p1, q1);
  }
  return 0;
}
Problem p00150 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
const int MAX_V = 10000; // 100???????????????????f???????¢\\????°???¬?????
int prime[MAX_V + 1];
int main() {
  int k, i, max, min, n; // 1????????f???????C0????????f????????????????????¢
  for (i = 2; i <= MAX_V; i++) {
    prime[i] = 1; // 2???????£????f????????????°??????¨
  }
  for (i = 2; i * i <= MAX_V; i++) {
    if (prime[i]) {
      for (k = 2 * i; k <= MAX_V; k += i) {
        prime[k] =
            0; // ???f??????2???{???????£????{?????????f????????????????????¢
      }
    }
  }
  while (scanf("%d", &n)) {
    if (n == 0)
      break;
    max = 0;
    min = 0;
    for (i = n; i > 0; i--) {
      if (prime[i] && prime[i - 2]) {
        max = i;
        min = max - 2;
        // printf("%d %d\\n",i-2,i);
        break;
      }
    }
    printf("%d %d\\n", min, max);
  }
  return 0;
}

Error: WA

Fixed submission:

#include <stdio.h>
const int MAX_V = 10000; // 100???????????????????f???????¢\\????°???¬?????
int prime[MAX_V + 1];
int main() {
  int k, i, max, min, n; // 1????????f???????C0????????f????????????????????¢
  for (i = 2; i <= MAX_V; i++) {
    prime[i] = 1; // 2???????£????f????????????°??????¨
  }
  for (i = 2; i * i <= MAX_V; i++) {
    if (prime[i]) {
      for (k = 2 * i; k <= MAX_V; k += i) {
        prime[k] =
            0; // ???f??????2???{???????£????{?????????f????????????????????¢
      }
    }
  }
  while (scanf("%d", &n)) {
    if (n == 0)
      break;
    max = 0;
    min = 0;
    for (i = n; i > 0; i++) {
      if (prime[i] && prime[i - 2]) {
        max = i;
        min = max - 2;
        // printf("%d %d\\n",i-2,i);
        break;
      }
    }
    printf("%d %d\\n", min, max);
  }
  return 0;
}
Problem p00150 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>

int isprime(int n) {
  int i;
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0)
      return 0;
  }
  return 1;
}

int main() {
  int k, suu, an1, an2;
  while (1) {
    scanf("%d", &suu);
    if (suu == 0)
      break;
    for (k = suu; k > 0; k--) {
      if (isprime(k - 2) == 1 && isprime(k) == 1) {
        an1 = k - 2;
        an2 = k;
        break;
      }
    }
    printf("%d %d\\n", an1, an2);
  }
}

Error: TLE

Fixed submission:

#include <stdio.h>

int isprime(int n) {
  int i;
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0)
      return 0;
  }
  return 1;
}

int main() {
  int k, suu, an1, an2;
  while (1) {
    scanf("%d", &suu);
    if (suu == 0)
      break;
    for (k = 2; k <= suu; k++) {
      if (isprime(k - 2) == 1 && isprime(k) == 1) {
        an1 = k - 2;
        an2 = k;
      }
    }
    printf("%d %d\\n", an1, an2);
  }
}
Problem p00150 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  int prime[10001] = {0};
  int i, j, n;
  for (i = 3; i <= 10000; i += 2) {
    prime[i] = 1;
  }
  prime[2] = 1;
  for (i = 3; i <= 100; i += 2) {
    if (prime[i] == 1) {
      for (j = 3; j <= 10000 / i; j += 2) {
        prime[i * j] = 0;
      }
    }
  }
  while (cin >> n && (n != 0)) {
    for (i = n; i >= 5; i--) {
      if (prime[i] == 1 && prime[i - 2] == 1) {
        cout << i - 2 << " " << i << endl;
        break;
      }
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  bool prime[10001];
  int i, j, n;
  for (i = 4; i <= 10000; i += 2) {
    prime[i] = false;
  }
  prime[2] = true;
  for (i = 3; i <= 10000; i += 2) {
    if (prime[i]) {
      for (j = 3; j <= 10000 / i; j += 2) {
        prime[i * j] = false;
      }
    }
  }
  while (cin >> n && (n != 0)) {
    for (i = n; i >= 7; i--) {
      if (prime[i] && prime[i - 2]) {
        cout << i - 2 << " " << i << endl;
      }
    }
  }
  return 0;
}
Problem p00150 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <iostream>
using namespace std;
int main() {
  // ツ素ツ青板青カツ青ャ
  const int NUM = 10001;
  bool prime[NUM];
  prime[0] = false;
  prime[1] = false;
  for (int i = 2; i < NUM; i++)
    prime[i] = true;
  for (int i = 2; i * i < NUM; i++)
    for (int k = 2; i * k < NUM; k++)
      prime[i * k] = false;

  int maxtwin[10001], twin;
  for (int i = 5; i < 10001; i++) {
    if (prime[i] && prime[i - 2])
      twin = i;
    maxtwin[i] = twin;
  }
  for (int n; scanf("%d", &n), n;) {
    cout << maxtwin[n] - 2 << " " << maxtwin[n] << endl;
  }
  return 0;
}

Error: -11

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  // ツ素ツ青板青カツ青ャ
  const int NUM = 10001;
  bool prime[NUM];
  prime[0] = false;
  prime[1] = false;
  for (int i = 2; i < NUM; i++)
    prime[i] = true;
  for (int i = 2; i * i < NUM; i++)
    for (int k = 2; i * k < NUM; k++)
      prime[i * k] = false;

  int maxtwin[10001], twin;
  for (int i = 5; i < 10001; i++) {
    if (prime[i] && prime[i - 2])
      twin = i;
    maxtwin[i] = twin;
  }
  for (int n; scanf("%d", n), n;) {
    cout << maxtwin[n] - 2 << " " << maxtwin[n] << endl;
  }
  return 0;
}
Problem p00150 (C++) — buggy submission, verdict: Runtime Error

#include <math.h>
#include <stdio.h>
#include <string>
const int MAX_V = 10000;
int prime[MAX_V + 1];

int isprime() {
  int i, k, v;
  for (i = 2; i <= MAX_V; i++) {
    prime[i] = 1;
  }
  for (i = 2; i * i <= MAX_V; i++) {
    if (prime[i]) {
      for (k = 2 * i; k <= MAX_V; k += i) {
        prime[k] = 0;
      }
    }
  }
}
int main() {
  int n, i;
  isprime();
  while (1) {
    scanf("%d", &n);
    if (n == 0) {
      break;
    }
    for (i = n; i >= 2; i--) {
      if (prime[i] == 1 && prime[i - 2] == 1) {
        printf("%d %d\\n", i - 2, i);
        break;
      }
    }
  }
  return 0;
}

Error: WA

Fixed submission:

#include <math.h>
#include <stdio.h>
#include <string>
const int MAX_V = 100;
int prime[MAX_V + 1];

int isprime() {
  int i, k, v;
  for (i = 2; i <= MAX_V; i++) {
    prime[i] = 1;
  }
  for (i = 2; i * i <= MAX_V; i++) {
    if (prime[i]) {
      for (k = 2 * i; k <= MAX_V; k += i) {
        prime[k] = 0;
      }
    }
  }
}
int main() {
  int n, i;
  while (1) {
    scanf("%d", &n);
    if (n == 0) {
      break;
    }
    isprime();
    for (i = n; i >= 2; i--) {
      if (prime[i] == 1 && prime[i - 2] == 1) {
        printf("%d %d\\n", i - 2, i);
        break;
      }
    }
  }
  return 0;
}
Problem p00150 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <math.h>
using namespace std;
int isPrime(int n) {
  if (n < 2)
    return 0;
  double sqrtn = sqrt(n);
  for (int i = 2; i <= sqrtn; i++) {
    if (n % i == 0)
      return 0;
  }
  return 1;
}
int main(void) {
  int n = 1;
  while (n) {
    cin >> n;
    for (int i = n; i > 0; i--) {
      if (isPrime(i) * isPrime(i - 2)) {
        cout << i - 2 << " " << i << endl;
        break;
      }
    }
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int isPrime(int n) {
  for (int i = 2; i < n; i++) {
    if (n % i == 0)
      return 0;
  }
  return 1;
}
int main(void) {
  int n = 1;
  while (n) {
    cin >> n;
    for (int i = n; i > 0; i--) {
      if (isPrime(i) * isPrime(i - 2)) {
        cout << i - 2 << " " << i << endl;
        break;
      }
    }
  }
  return 0;
}