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

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, j, k) for (int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define repr(i, j) for (int i = j; i >= 0; --i)
#define INF (1 << 30)
#define MOD 1e9 + 7

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define PRIM 50021

bool prim[50022];
int a_prime[50022];

int main() {
  memset(prim, true, sizeof(prim));
  int N;
  prim[0] = false;
  FOR(i, 1, sqrt(PRIM)) {
    if (prim[i]) {
      for (int j = (i + 1); (i + 1) * j <= PRIM; ++j) {
        prim[(i + 1) * j - 1] = false;
      }
    }
  }
  while (cin >> N) {
    repr(i, N - 2) {
      if (prim[i]) {
        printf("%d ", i + 1);
        break;
      }
    }
    FOR(i, N, PRIM) {
      if (prim[i]) {
        printf("%d\\n", i + 1);
        break;
      }
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, j, k) for (int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define repr(i, j) for (int i = j; i >= 0; --i)
#define INF (1 << 30)
#define MOD 1e9 + 7

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define PRIM 50021

bool prim[50022];
int a_prime[50022];

int main() {
  memset(prim, true, sizeof(prim));
  int N;
  prim[0] = false;
  FOR(i, 1, sqrt(PRIM)) {
    if (prim[i]) {
      for (int j = (i + 1); (i + 1) * j <= PRIM; ++j) {
        prim[(i + 1) * j - 1] = false;
      }
    }
  }
  while (scanf("%d", &N)) {
    repr(i, N - 2) {
      if (prim[i]) {
        printf("%d ", i + 1);
        break;
      }
    }
    FOR(i, N, PRIM) {
      if (prim[i]) {
        printf("%d\\n", i + 1);
        break;
      }
    }
  }
  return 0;
}
Problem p00044 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>

using namespace std;

bool prime_table[100000];
int n;

void make_table() {
  for (int i = 0; i < 100000; i++)
    prime_table[i] = true;

  prime_table[0] = false;
  prime_table[1] = false;

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

void solve() {
  int i;
  for (i = n - 1; !prime_table[i]; i--)
    ;

  int j;
  for (j = n + 1; !prime_table[j]; j++)
    ;
  cout << i << ' ' << j << endl;
}

int main() {
  make_table();
  while (cin >> n) {
    solve();
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>

using namespace std;

bool prime_table[10000];
int n;

void make_table() {
  for (int i = 0; i < 10000; i++)
    prime_table[i] = true;

  prime_table[0] = false;
  prime_table[1] = false;

  for (int i = 2; i + i < 10000; i++) {
    if (prime_table[i]) {
      for (int j = i + i; j < 10000; j += i) {
        prime_table[j] = false;
      }
    }
  }
}

void solve() {
  int min, max;
  int i;
  for (i = n - 1; !prime_table[i]; i--)
    ;
  min = i;

  int j;
  for (j = n + 1; !prime_table[j]; j++)
    ;
  max = j;
  cout << i << ' ' << j << endl;
}

int main() {
  make_table();
  while (cin >> n) {
    solve();
  }
  return 0;
}
Problem p00044 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>
int table[55000];

int main() {
  for (int i = 2; i < 1000; i++) {
    if (table[i] == 0) {
      for (int j = i * 2; j <= 55000; j += i) {
        table[j] = 1;
      }
    }
  }
  int a;
  while (~scanf("%d", &a)) {
    int i;
    for (i = a - 1; table[i] == 1; i--)
      ;
    printf("%d ", i);
    for (i = a + 1; table[i] == 1; i++)
      ;
    printf("%d\\n", i);
  }
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int table[80000] = {};
  for (int i = 2; i * i < 80000; ++i) {
    if (!table[i]) {
      for (int j = i * 2; j <= 80000; j += i) {
        table[j] = 1;
      }
    }
  }

  int n;
  while (cin >> n, n) {
    int i;
    for (i = n - 1; table[i]; --i)
      ;
    cout << i << " ";
    for (i = n + 1; table[i]; ++i)
      ;
    cout << i << endl;
  }
  return 0;
}
Problem p00044 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>
using namespace std;
#define NUM 100000
int main(void) {
  vector<bool> is_prime(NUM + 1, false);
  is_prime[2] = true;
  for (int i = 3; i < NUM; i += 2) {
    is_prime[i] = true;
  }
  for (int i = 3; i < NUM; i += 2) {
    if (is_prime[i]) {
      for (int j = i + i; j < NUM; j += i) {
        is_prime[j] = false;
      }
    }
  }

  int n;
  while (cin >> n) {
    for (int i = n - 1; i >= 2; i--) {
      if (is_prime[i]) {
        cout << i << " ";
        break;
      }
    }

    for (int i = n + 1; i <= NUM; i++) {
      if (is_prime[i]) {
        cout << i << endl;
        break;
      }
    }
  }

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;
#define MAX 60000
int main(void) {
  vector<bool> primes(MAX + 1, false);
  for (int i = 3; i <= MAX; i += 2)
    primes[i] = true;
  primes[0] = false;
  primes[1] = false;
  primes[2] = true;

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

  int n;
  while (cin >> n) {
    int max = 0, min = 0;
    int p = n + 2;
    while (!min) {
      if (primes[p])
        min = p;
      else
        p += 2;
    }
    p = n % 2 ? n : n - 1;
    p -= 2;
    while (!max) {
      if (primes[p])
        max = p;
      else
        p -= 2;
    }

    cout << max << " " << min << endl;
  }
}
Problem p00044 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
#define rep(i, a) for (int i = 0; i < a; i++)
#define loop(i, a, b) for (int i = a; i < b; i++)
const int M = (1e6);
int p[M];
void isPrime() {
  rep(i, M) p[i] = true;
  p[0] = p[1] = false;
  loop(i, 2, M) {
    if (p[i])
      for (int j = i + i; j < M; j += i)
        p[j] = false;
  }
}
int main(void) {
  isPrime();
  int n;
  while (cin >> n) {
    int i = n - 1;
    while (!p[i--])
      ;
    cout << ++i << " ";
    i = n + 1;
    while (!p[i++])
      ;
    cout << --i << endl;
  }
}

Error: 0

Fixed submission:

#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
#define rep(i, a) for (int i = 0; i < a; i++)
#define loop(i, b, a) for (int i = b; i < a; i++)
const int MAX = 50000;
bool p[MAX];
void isPrime() {
  fill(p, p + MAX, true);
  p[0] = p[1] = false;
  rep(i, MAX) {
    if (p[i]) {
      for (int j = i + i; j < MAX; j += i)
        p[j] = false;
    }
  }
}

int main(void) {
  isPrime();
  int n;
  while (cin >> n) {

    int i;

    for (i = n - 1; !p[i]; i--)
      ;
    cout << i << " ";
    for (i = n + 1; !p[i]; i++)
      ;
    cout << i << endl;
  }
  return 0;
}
Problem p00044 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
using namespace std;
int main() {
  int n;
  bool isprime[70001];
  int prime[35000];
  int pnum = 0;
  fill(isprime, isprime + 70001, true);
  isprime[0] = isprime[1] = false;
  for (int i = 2; i < 70001; i++) {
    if (isprime[i]) {
      for (int j = i + i; j < 70001; j += i)
        isprime[j] = false;
    }
  }
  for (int i = 2; i < 70001; i++) {
    if (isprime[i]) {
      prime[pnum++] = i;
    }
  }
  /*	for (int i=0; i<100; i++) {
                  printf("%d ",prime[i]);
          }
          printf("\\n");
  */
  while (scanf("%d", &n) != EOF) {
    int a, b;
    for (int i = 0; i < 35000; i++) {
      if (prime[i] > n) {
        a = prime[i - 1];
        b = prime[i];
        break;
      } else if (prime[i] == n) {
        a = prime[i - 1];
        b = prime[i + 1];
        break;
      }
    }
    printf("%d %d\\n", a, b);
  }
}

Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int n;
  while (cin >> n) {
    vector<int> pl(n * n, 0);
    vector<int> res(2);
    pl[2] = 1;
    for (int i = 3; i < n * n; i += 2)
      pl[i] = 1;
    for (int i = 3; i < n; i += 2) {
      if (pl[i] == 0)
        continue;
      for (int j = i * 2; j <= n * n; j += i)
        pl[j] = 0;
    }
    for (int i = n; i > 0; i--) {
      if (pl[i] == 1) {
        res[0] = i;
        break;
      }
    }
    for (int i = n; i < n * n; i++) {
      if (pl[i] == 1) {
        res[1] = i;
        break;
      }
    }
    cout << res[0] << " " << res[1] << endl;
  }
}
Problem p00044 (C++) — buggy submission, verdict: Runtime Error

#include <cmath>
#include <iostream>
#define Int int
using namespace std;

const int MAX_NUM = 500000;
bool prime_number[MAX_NUM];

void isPrime() {
  fill(prime_number, prime_number + MAX_NUM, true);
  prime_number[0] = prime_number[1] = false;

  for (int i = 2; i < MAX_NUM; i++) {
    if (prime_number[i])
      for (int j = 2; i * j < MAX_NUM; j++) {
        prime_number[i * j] = false;
      }
  }
}
int main(void) {
  int n;
  isPrime();
  while (cin >> n) {
    int i;

    for (i = (!prime_number[n] ? n : n - 1); !prime_number[i]; i--)
      ;
    cout << i << " ";
    for (i = (!prime_number[n] ? n : n + 1); !prime_number[i]; i++)
      ;
    cout << i << endl;
  }
}

Error: 0

Fixed submission:

#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
#define rep(i, a) for (int i = 0; i < a; i++)
#define loop(i, b, a) for (int i = b; i < a; i++)
const int MAX = 50000;
bool p[MAX];
void isPrime() {
  fill(p, p + MAX, true);
  p[0] = p[1] = false;
  rep(i, MAX) {
    if (p[i]) {
      for (int j = i + i; j < MAX; j += i)
        p[j] = false;
    }
  }
}

int main(void) {
  isPrime();
  int n;
  while (cin >> n) {
    int i = n - 1;
    while (!p[i--])
      ;
    cout << ++i << ' ';
    i = n + 1;
    while (!p[i++])
      ;
    cout << --i << endl;
  }
  return 0;
}
Problem p00044 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
#define rep(i, a) for (int i = 0; i < a; i++)
#define loop(i, b, a) for (int i = b; i < a; i++)
const int MAX = 1000000;
int main(void) {
  bool prime[MAX];
  rep(i, MAX) prime[i] = true;
  prime[0] = prime[1] = false;
  loop(i, 2, i * i) {
    if (prime[i]) {
      for (int j = i + i; j < MAX; j += i) {
        prime[j] = false;
      }
    }
  }
  // rep(i,100)if(prime[i])cout<<i<<endl;
  int n;
  while (cin >> n) {
    int mi, ma;
    mi = n - 1;
    ma = ++n;
    while (!prime[mi]) {
      mi--;
    }
    while (!prime[ma]) {
      ma++;
    }

    cout << mi << " " << ma << endl;
  }
}

Error: TLE

Fixed submission:

#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
#define rep(i, a) for (int i = 0; i < a; i++)
int main(void) {
  int w;
  int n;
  int num = 0;
  while (cin >> w, w) {
    cout << "Case " << ++num << ":" << endl;
    cin >> n;
    vector<pair<int, int>> in(n);
    rep(i, n) {
      int a, b;
      scanf("%d,%d", &a, &b);
      in[i] = make_pair(a, b);
    }
    int resw = 0;
    int resm = 0;
    int last = 1 << n;
    for (int i = 1; i < last + 1; i++) {
      // cout<<i<<endl;
      int nw = 0;
      int money = 0;
      rep(j, n - 1) {
        bool use = (i / (1 << j)) % 2;
        if (use) {
          money += in[j].first;
          nw += in[j].second;
        }
      }
      if (nw > w)
        continue;
      if (resm < money) {
        // rep(k,n-1)cout<<(i/(1<<k))%2<<" ";
        // cout<<endl;

        resm = money;
        resw = nw;
      }
      if (money == resm && resw < nw) {
        resw = nw;
      }
      // cout<<i<<" "<<resw<<endl;
      // cout<<endl;
    }
    cout << resm << endl << resw << endl;

    //*/
  }
}
Problem p00044 (C++) — buggy submission, verdict: Runtime Error

#include <cmath>
#include <iostream>
#define Int int
using namespace std;

const int MAX_NUM = 500000;
bool prime_number[MAX_NUM];

void isPrime() {
  fill(prime_number, prime_number + MAX_NUM, true);
  prime_number[0] = prime_number[1] = false;

  for (int i = 2; i < MAX_NUM; i++) {
    if (prime_number[i])
      for (int j = 2; i * j < MAX_NUM; j++) {
        prime_number[i * j] = false;
      }
  }
}
int main(void) {
  int n;
  isPrime();
  while (cin >> n) {
    int i;

    for (i = (!prime_number[n] ? n : n - 1); !prime_number[i]; i--)
      ;
    cout << i << " ";
    for (i = (!prime_number[n] ? n : n + 1); !prime_number[i]; i++)
      ;
    cout << i << endl;
  }
}

Error: WA

Fixed submission:

#include <iostream>

using namespace std;

const int MAX_NUM = 50000;
bool prime_number[MAX_NUM];

void prime_create() {
  fill(prime_number, prime_number + MAX_NUM, true);
  prime_number[0] = prime_number[1] = false;

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

int main(void) {
  prime_create();
  int n;
  while (cin >> n) {
    int i;

    for (i = (!prime_number[n] ? n : n - 1); !prime_number[i]; i--)
      ;
    cout << " " << i << " ";
    for (i = (!prime_number[n] ? n : n + 1); !prime_number[i]; i++)
      ;
    cout << i << endl;
  }
}
Problem p00044 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>
using namespace std;
#define MAX 100001

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

int main() {
  int n;
  calcPrime();
  while (cin >> n) {
    int under = -1, over = -1;
    for (int d = n, u = n; 2 < d || u < MAX;) {
      if (under != -1 && over != -1)
        break;
      if (under == -1 && 2 < d) {
        d--;
        if (prime[d])
          under = d;
      }
      if (over == -1 && u < MAX) {
        u++;
        if (prime[u])
          over = u;
      }
    }
    cout << under << " " << over << endl;
  }
}

Error: TLE

Fixed submission:

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

bool prime[MAX];
void calcPrime() {
  for (int i = 2; i < MAX; i++)
    prime[i] = true;
  for (int i = 2; i < MAX; i++) {
    if (prime[i]) {
      for (int j = i + i; j <= MAX; j += i) {
        prime[j] = false;
      }
    }
  }
}

int main() {
  int n;
  calcPrime();
  while (cin >> n) {
    int under = -1, over = -1;
    for (int d = n - 1, u = n + 1; 0 < d || u < MAX;) {
      if (2 < d)
        d--;
      if (u < MAX)
        u++;
      if (under != -1 && over != -1)
        break;
      if (prime[d])
        under = d;
      if (prime[u])
        over = u;
    }
    cout << under << " " << over << endl;
  }
}
Problem p00044 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <iostream>
using namespace std;
int main(void) {
  int i, no, input;
  int prime[10000];
  int ptr = 0, c = 0;
  int flag = 0;
  int last;

  while (cin >> input) {
    flag = ptr = c = 0;
    prime[ptr++] = 2;
    prime[ptr++] = 3;
    for (no = 5;; no += 2) {
      if (flag == 2) {
        break;
      }
      if (input + 1 <= no) {
        flag = 1;
        c++;
      }
      if (c == 1) {
        if (input == prime[ptr - 1])
          last = ptr - 2;
        else
          last = ptr - 1;
      }
      for (i = 1; i < ptr; i++) {
        if (no % prime[i] == 0)
          break;
      }
      if (ptr == i) {
        prime[ptr++] = no;
        if (flag == 1) {
          flag = 2;
        }
      }
    }

    printf("%d %d\\n", prime[last], prime[ptr - 1]);
  }
  return 0;
}

Error: 0

Fixed submission:

#include <cstdio>
#include <iostream>
using namespace std;
int main(void) {
  int i, no, input;
  int prime[500];
  int ptr = 0, c = 0;
  int flag = 0;
  int last;

  while (cin >> input) {
    flag = ptr = c = 0;
    prime[ptr++] = 2;
    prime[ptr++] = 3;
    for (no = 5;; no += 2) {
      if (flag == 2) {
        break;
      }
      if (input + 1 <= no) {
        flag = 1;
        c++;
      }
      if (c == 1) {
        if (input == prime[ptr - 1])
          last = ptr - 2;
        else
          last = ptr - 1;
      }
      for (i = 1; i < ptr; i++) {
        if (no % prime[i] == 0)
          break;
      }
      if (ptr == i) {
        prime[ptr++] = no;
        if (flag == 1) {
          flag = 2;
        }
      }
    }

    printf("%d %d\\n", prime[last], prime[ptr - 1]);
  }
  return 0;
}
Problem p00044 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  vector<int> primes;
  vector<int> is_prime(60001, 1);
  is_prime[0] = is_prime[1] = 0;
  int lim = (int)sqrt(60000);
  for (int i = 2; i <= lim; ++i) {
    if (is_prime[i]) {
      if (i < lim) {
        for (int j = i * i; j <= 60000; j += i)
          is_prime[j] = 0;
      }
    }
  }
  for (int i = 2; i <= 60000; ++i)
    if (is_prime[i])
      primes.push_back(i);

  int n;
  while (cin >> n) {
    cout << *(lower_bound(primes.begin(), primes.end(), n) - 1) << ' '
         << *upper_bound(primes.begin(), primes.end(), n) << endl;
  }
  return 0;
}

Error: WA

Fixed submission:

// Name: Puzzle
// Level: 2
// Category: V~[V,[³DæTõ,STõ
// Note:

/*
 * ÌÒ¿»èB
 * »ê¼êÌvðÁ¦ÄÝÄAðÉÈé©»è·êÎæ¢B
 * »èÍªðÅÉæÁÄAÉ4ñqAqÌæè©½ðSTõ·éB
 */
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

bool rec(vector<int> &v, int level) {
  if (level == 5)
    return true;
  // ª
  if (level == 0) {
    for (int i = 0; i < v.size(); ++i) {
      if (v[i] >= 2) {
        v[i] -= 2;
        if (rec(v, level + 1))
          return true;
        v[i] += 2;
      }
    }
  } else {
    // q
    for (int i = 0; i < v.size() - 2; ++i) {
      if (v[i] >= 1 && v[i + 1] >= 1 && v[i + 2] >= 1) {
        v[i]--;
        v[i + 1]--;
        v[i + 2]--;
        if (rec(v, level + 1))
          return true;
        v[i]++;
        v[i + 1]++;
        v[i + 2]++;
      }
    }
    // q
    for (int i = 0; i < v.size(); ++i) {
      if (v[i] >= 3) {
        v[i] -= 3;
        if (rec(v, level + 1))
          return true;
        v[i] += 3;
      }
    }
  }
  return false;
}

bool check(const vector<int> &v) {
  vector<int> tmp = v;
  return rec(tmp, 0);
}

int main() {
  string line;
  while (cin >> line) {
    vector<int> cnt(9, 0);
    for (int i = 0; i < line.size(); ++i)
      cnt[line[i] - '1']++;
    vector<int> v;
    for (int i = 1; i <= 9; ++i) {
      if (cnt[i - 1] == 4)
        continue;
      cnt[i - 1]++;
      if (check(cnt))
        v.push_back(i);
      cnt[i - 1]--;
    }
    if (v.size() == 0)
      v.push_back(0);
    for (int i = 0; i < v.size(); ++i) {
      if (i > 0)
        cout << ' ';
      cout << v[i];
    }
    cout << endl;
  }
  return 0;
}
Problem p00044 (C++) — buggy submission, verdict: Runtime Error

#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
bool prime[50022];
void eratos() {
  memset(prime, true, sizeof(prime));
  prime[0] = false;
  prime[1] = false;
  for (int i = 2; i * i < 50022; i++) {
    if (!prime[i])
      continue;
    for (int j = i * 2; j < 50022; j += i) {
      prime[j] = false;
    }
  }
  return;
}
int main() {
  int n, k, s;
  eratos();
  while (scanf("%d", &n) != EOF) {
    for (int i = n - 1;; i--) {
      if (prime[i]) {
        k = i;
        break;
      }
    }
    for (int i = n + 1;; i++) {
      if (prime[i]) {
        s = i;
        break;
      }
    }
    printf("%d %d\\n", k, s);
  }
  return 0;
}

Error: 0

Fixed submission:

#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
bool prime[50001];
void eratos() {
  memset(prime, true, sizeof(prime));
  prime[0] = false;
  prime[1] = false;
  for (int i = 2; i <= sqrt((double)50001) + 1; i++) {
    if (!prime[i])
      continue;
    for (int j = i * 2; j < 50001; j += i) {
      prime[j] = false;
    }
  }
  return;
}
int main() {
  int n, k, s;
  eratos();
  while (scanf("%d", &n) != EOF) {
    for (int i = n - 1;; i--) {
      if (prime[i]) {
        k = i;
        break;
      }
    }
    for (int i = n + 1;; i++) {
      if (prime[i]) {
        s = i;
        break;
      }
    }
    printf("%d %d\\n", k, s);
  }
  return 0;
}
Problem p00044 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int main() {
  bool num[1000001] = {false};
  for (int i = 2; i < 1000; i++)
    if (!num[i])
      for (int j = i * i; j < 1000001; j += i)
        num[j] = true;
  for (int n; cin >> n;) {
    for (int i = n - 1;; i--)
      if (!num[i]) {
        cout << i << " ";
        break;
      }
    for (int i = n + 1;; i++)
      if (!num[i]) {
        cout << i << endl;
        break;
      }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  bool num[10001] = {false};
  for (int i = 2; i < 100; i++)
    if (!num[i])
      for (int j = i * i; j < 10001; j += i)
        num[j] = true;
  for (int n; cin >> n;) {
    for (int i = n - 1;; i--)
      if (!num[i]) {
        cout << i << " ";
        break;
      }
    for (int i = n + 1;; i++)
      if (!num[i]) {
        cout << i << endl;
        break;
      }
  }
  return 0;
}
Problem p00044 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

int main() {
  int n;

  while (cin >> n) {
    int ans_ma;
    int ma_n = n + 1;
    int c_ma = 0;

    if (ma_n % 2 == 0) {
      ++ma_n;
    }
    for (int i = ma_n;; i = i + 2) {
      int q = sqrt(i);

      c_ma = 1;
      for (int j = 3; j <= q; j = j + 2) {
        if (i % j == 0) {
          c_ma = 0;
          break;
        }
      }
      if (c_ma == 1) {
        ans_ma = i;
        break;
      }
    }

    int ans_mi;
    int mi_n = n - 1;
    int c_mi = 0;

    if (mi_n == 2) {
      ans_mi = 2;
    } else {
      if (mi_n % 2 == 0) {
        --mi_n;
      }
      for (int i = mi_n; i >= 3; i = i - 2) {
        int q = sqrt(i);

        c_mi = 1;
        for (int j = 3; j <= q; j = j + 2) {
          if (i % j == 0) {
            c_mi = 0;
            break;
          }
        }
        if (c_mi == 1) {
          ans_mi = i;
          break;
        }
      }
    }
    cout << ans_mi << " " << ans_ma << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main() {
  int n;

  while (cin >> n) {
    int ans_mi, ans_ma;
    int mi_n = n - 1;
    int ma_n = n + 1;
    int c_mi = 0;
    int c_ma = 0;

    if (ma_n % 2 == 0) {
      ++ma_n;
    }
    for (int i = ma_n;; i = i + 2) {
      int q = sqrt(i);

      if (q < 3) {
        ans_mi = q;
        break;
      }

      else {
        c_ma = 1;
        for (int j = 3; j <= q; j = j + 2) {
          if (i % j == 0) {
            c_ma = 0;
            break;
          }
        }
        if (c_ma == 1) {
          ans_ma = i;
        }
      }
    }

    if (mi_n == 2) {
      ans_mi = 2;
    } else {
      if (mi_n % 2 == 0) {
        --mi_n;
      }
      for (int i = mi_n; i > 2; i = i - 2) {
        int q = sqrt(i);

        if (q < 3) {
          ans_mi = q;
          break;
        } else {
          c_mi = 1;
          for (int j = 3; j <= q; j = j + 2) {
            if (i % j == 0) {
              c_mi = 0;
              break;
            }
          }
          if (c_mi == 1) {
            ans_mi = i;
          }
        }
      }
    }
  }
  return 0;
}