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

#include <algorithm>
#include <iostream>
#define SEISEKI 10000000

using namespace std;

int main() {
  while (1) {
    int n;
    int ans = SEISEKI;

    cin >> n;
    int a[1001];
    if (n == 0)
      break;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }

    sort(a, a + n); // 昇順

    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        ans = min(ans, abs(a[i] - a[j]));
      }
    }
    cout << ans << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#define SEISEKI 10000000

using namespace std;

int main() {
  while (1) {
    int n;
    int ans = SEISEKI;

    cin >> n;
    int a[1001];
    if (n == 0)
      break;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }

    // sort(a, a+n);	//昇順

    for (int i = 0; i < n; i++) {
      for (int j = n - 1; j >= 0; i--) {
        ans = min(ans, a[i] - a[i - j]);
      }
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p01094 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  while (1) {
    int n;
    cin >> n;

    if (n == 0)
      break;

    char c[100];
    for (int i = 0; i < n; i++) {
      cin >> c[i];
    }

    int cnt[26] = {0};

    for (int i = 0; i < n; i++) {
      cnt[(int)(c[i] - 'A')]++;

      int max1 = -1;
      int max2 = -1;

      for (int j = 0; j < 26; j++) {
        if (cnt[j] > max1) {
          max2 = max1;
          max1 = cnt[j];
        } else if (cnt[j] > max2) {
          max2 = cnt[j];
        }
      }

      if (max1 - max2 > n - (i + 1)) {
        for (int j = 0; j < 26; j++) {
          if (cnt[j] == max1) {
            cout << (char)(j + 'A') << " ";
            break;
          }
        }
        cout << (i + 1) << endl;
        break;
      }

      if (i == (n - 1)) {
        cout << "TIE" << endl;
        break;
      }
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  while (1) {
    int n;
    cin >> n;

    char c[100];
    for (int i = 0; i < n; i++) {
      cin >> c[i];
    }

    int cnt[26] = {0};

    for (int i = 0; i < n; i++) {
      cnt[(int)(c[i] - 'A')]++;

      int max1 = -1;
      int max2 = -1;

      for (int j = 0; j < 26; j++) {
        if (cnt[j] > max1) {
          max2 = max1;
          max1 = cnt[j];
        } else if (cnt[j] > max2) {
          max2 = cnt[j];
        }
      }

      if (max1 - max2 > n - (i + 1)) {
        for (int j = 0; j < 26; j++) {
          if (cnt[j] == max1) {
            cout << (char)(j + 'A') << " ";
            break;
          }
        }
        cout << (i + 1) << endl;
        break;
      }

      if (i == (n - 1)) {
        cout << "TIE" << endl;
        break;
      }
    }
  }

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

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

using namespace std;
using ll = long long;

int main() {
  while (true) {
    int n;
    cin >> n;
    if (n == 0) {
      break;
    }
    vector<int> num(100, 0);
    int fin = 1000000;
    int maxind = 0;
    for (int i = 0; i < n; i++) {
      const int rest = n - i - 1;
      char C;
      cin >> C;
      num[C - 'A']++;
      int maxind1 = -1;
      int max1 = -1;
      int maxind2 = -1;
      int max2 = -1;
      for (int i = 0; i < 100; i++) {
        if (max1 == -1) {
          maxind1 = 0;
          max1 = num[0];
        } else if (max2 == -1) {
          maxind1 = (num[0] > num[1]) ? 0 : 1;
          max1 = max(num[0], num[1]);
          maxind2 = 1 - maxind1;
          max2 = min(num[0], num[1]);
        } else {
          if (num[i] >= max1) {
            max2 = max1;
            maxind2 = maxind1;
            max1 = num[i];
            maxind1 = i;
          } else if (num[i] > max2) {
            max2 = num[i];
            maxind2 = i;
          }
        }
      }
      if (max1 > max2 + rest) {
        fin = min(fin, i + 1);
        maxind = maxind1;
      }
    }
    if (fin == 1000000) {
      cout << "TIE" << endl;
    } else {
      cout << (char)(maxind + 'A') << " " << fin << endl;
    }
  }

  return 0;
}

Error: -6
double free or corruption (out)


Fixed submission:

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

using namespace std;
using ll = long long;

int main() {
  while (true) {
    int n;
    cin >> n;
    if (n == 0) {
      break;
    }
    vector<int> num(100, 0);
    vector<int> c(n, 0);
    bool tie = true;
    for (int i = 0; i < n; i++) {
      const int rest = n - i - 1;
      cin >> c[i];
      c[i]--;
      num[c[i]]++;
      int max1 = -1;
      int max2 = -1;
      for (int i = 0; i < 100; i++) {
        if (max1 == -1) {
          max1 = num[0];
        } else if (max2 == -1) {
          max1 = max(num[0], num[1]);
          max2 = min(num[0], num[1]);
        } else {
          if (num[i] >= max1) {
            max2 = max1;
            max1 = num[i];
          } else if (num[i] > max2) {
            max2 = num[i];
          }
        }
      }
      if (max1 > max2 + rest) {
        cout << i + 1 << endl;
        tie = false;
        break;
      }
    }
    if (tie) {
      cout << "TIE" << endl;
    }
  }

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

#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <vector>
#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--)

using namespace std;

using Cand = tuple<int, int>;

int get_name(const Cand &c) { return get<0>(c); }
int get_point(const Cand &c) { return get<1>(c); }

tuple<Cand, Cand> get_top_two_cands(const vector<int> &point) {
  Cand top = make_tuple(-1, -1), second = make_tuple(-1, -1);
  REP(j, 26) {
    if (point[j] > get_point(top)) {
      second = top;
      top = make_tuple(j, point[j]);
    } else if (point[j] > get_point(second)) {
      second = make_tuple(j, point[j]);
    }
  }
  return make_tuple(top, second);
}

int main() {
  int N;
  while (cin >> N && N) {
    vector<char> C(N);
    REP(i, N) { cin >> C[i]; }

    vector<int> point(26, 0);
    int votes = 0;
    Cand top = make_tuple(0, 0), second = make_tuple(0, 0);
    for (; votes < N && (N - votes) >= (get_point(top) - get_point(second));
         ++votes, tie(top, second) = get_top_two_cands(point)) {
      ++point[C[votes] - 'A'];
    }
    if (get_point(top) > get_point(second)) {
      char name = 'A' + get_name(top);
      cout << name << " " << votes << endl;
    } else {
      cout << "TIE" << endl;
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <vector>
#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--)

using namespace std;

using Cand = tuple<int, int>;

int get_name(const Cand &c) { return get<0>(c); }
int get_point(const Cand &c) { return get<1>(c); }

tuple<Cand, Cand> get_top_two_cands(const vector<int> &point) {
  Cand top = make_tuple(-1, -1), second = make_tuple(-1, -1);
  REP(j, 26) {
    if (point[j] > get_point(top)) {
      second = top;
      top = make_tuple(j, point[j]);
    } else if (point[j] > get_point(second)) {
      second = make_tuple(j, point[j]);
    }
  }
  return make_tuple(top, second);
}

int main() {
  int N;
  while (cin >> N && N) {
    vector<char> C(26);
    REP(i, N) { cin >> C[i]; }

    vector<int> point(26, 0);
    int votes = 0;
    Cand top = make_tuple(0, 0), second = make_tuple(0, 0);
    for (; votes < N && (N - votes) >= (get_point(top) - get_point(second));
         ++votes, tie(top, second) = get_top_two_cands(point)) {
      ++point[C[votes] - 'A'];
    }
    if (get_point(top) > get_point(second)) {
      char name = 'A' + get_name(top);
      cout << name << " " << votes << endl;
    } else {
      cout << "TIE" << endl;
    }
  }
  return 0;
}
Problem p01094 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main() {
  while (true) {
    int n;
    cin >> n;
    if (n == 0)
      break;

    char c[n];
    for (int i = 0; i < n; i++) {
      cin >> c[i];
    }

    int can[26] = {0}; //????£????(candidate)????\\¨??°

    for (int i = 0; i < n; i++) {
      can[(int)(c[i] - 'A')]++;

      int max1 = -1; //??????
      int max2 = -1; //??????

      // A~Z???????\\¨??°???????????????
      for (int j = 0; j < 26; j++) {
        if (can[j] > max1) {
          max2 = max1;
          max1 = can[j];
        } else if (can[j] > max2) {
          max2 = can[j];
        }
      }

      //????????????????????????????\\¨??°???????????????
      if (max1 - max2 > n - (i + 1)) {
        for (int j = 0; j < 26; j++) {
          if (can[j] == max1) {
            cout << (char)(j + 'A') << ' ';
            break;
          }
        }
        cout << (i + 1) << endl;
        break;
      }

      //???????????§????\\¨????????´???
      if (i == n - 1) {
        cout << "TIE" << endl;
        break;
      }
    }
  }

  return 0;
}

Error: -7

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  while (true) {
    int n;
    cin >> n;
    if (n == 0)
      break;

    int c[n];
    for (int i = 0; i < n; i++) {
      cin >> c[i];
    }

    int can[26] = {0}; //????£????(candidate)????\\¨??°

    for (int i = 0; i < n; i++) {
      can[(int)(c[i] - 'A')]++;

      int max1 = -1; //??????
      int max2 = -1; //??????

      // A~Z???????\\¨??°???????????????
      for (int j = 0; j < 26; j++) {
        if (can[j] > max1) {
          max2 = max1;
          max1 = can[j];
        } else if (can[j] > max2) {
          max2 = can[j];
        }
      }

      //????????????????????????????\\¨??°???????????????
      if (max1 - max2 > n - (i + 1)) {
        for (int j = 0; j < 26; j++) {
          if (can[j] == max1) {
            cout << (char)(j + 'A') << ' ';
            break;
          }
        }
        cout << (i + 1) << endl;
        break;
      }

      //???????????§????\\¨????????´???
      if (i == n - 1) {
        cout << "TIE" << endl;
        break;
      }
    }
  }

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

#include <bits/stdc++.h>

using namespace std;

#define INF 1e9

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

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

    if (n == 0)
      break;

    int sum[30] = {};
    char ans;
    int t = -1;
    bool f = false;

    for (int i = 0; i < n; i++) {
      char c;
      cin >> c;

      sum[c - 'A']++;

      int Max1 = 0, Max2 = 0;
      char C;

      for (int i = 0; i < 26; i++) {
        if (Max1 < sum[i]) {
          Max2 = Max1;
          Max1 = sum[i];
          C = 'A' + i;
        } else if (Max2 < sum[i]) {
          Max2 = sum[i];
        }
      }

      if (Max1 > Max2 + n - i - 1 && !f) {
        ans = C;
        t = i + 1;
        f = true;
      }
    }

    if (f) {
      cout << ans << " " << t << endl;
    } else
      cout << "TIE" << endl;
  }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define INF 1e9

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

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

    int sum[30] = {};
    char ans;
    int t = -1;
    bool f = false;

    for (int i = 0; i < n; i++) {
      char c;
      cin >> c;

      sum[c - 'A']++;

      int Max = 0;

      for (int i = 0; i < 26; i++) {
        if (i == c - 'A')
          continue;
        Max = max(Max, sum[i]);
      }

      if (sum[c - 'A'] > Max + n - i - 1 && !f) {
        ans = c;
        t = i + 1;
        f = true;
      }
    }

    if (f) {
      cout << ans << " " << t << endl;
    } else
      cout << "TIE" << endl;
  }
}
Problem p01094 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int N;

struct alpha_t {
  int value;
  char index;
  bool operator<(const alpha_t &other) const { return value < other.value; }
};

typedef pair<char, int> P;

vector<int> tokuhyou(26);

P check() {
  priority_queue<alpha_t> que;
  for (int i = 0; i < 26; i++) {
    alpha_t tmp;
    tmp.value = tokuhyou[i];
    tmp.index = (char)i + 'A';
    que.push(tmp);
  }
  alpha_t tmp1, tmp2;
  tmp1 = que.top();
  que.pop();
  tmp2 = que.top();
  que.pop();
  //  cout << tmp1.index << " " << tmp1.value << endl;
  return P(tmp1.index, tmp1.value - tmp2.value);
}

int main() {
  while (true) {
    cin >> N;
    bool flag = false;
    if (N == 0)
      break;
    for (int i = 0; i < 26; i++)
      tokuhyou[i] = 0;
    for (int count = 0; count < N; count++) {
      char hito;
      cin >> hito;
      tokuhyou[(int)(hito - 'A')]++;
      //      cout << "debug: " << check().second << " " << N - count - 1<<
      //      endl;
      if (check().second > N - count - 1) {
        if (flag == false)
          cout << check().first << " " << count + 1 << endl;
        flag = true;
      }
    }
    if (flag == true)
      continue;
    else if (check().second == 0)
      cout << "TIE" << endl;
    else
      cout << check().first << " " << N + 1 << endl;
  }
}

Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>

const int max = 7368792;
bool prime[max] = {false};
int main() {
  while (true) {
    int m, n;

    std::cin >> m >> n;

    if (m == 0 && n == 0)
      break;
    for (int i = 0; i < max; ++i) {
      prime[i] = false;
    }
    for (int i = 1; i * m < max; ++i) {
      prime[i * m] = true;
    }
    int k = n - 1;

    int i;
    for (i = m + 1; i < max; ++i) {
      if (prime[i] == false) {
        if (k != 0) {
          k--;
          for (int j = 1; i * j < max; ++j) {
            prime[j * i] = true;
          }
        } else {
          break;
        }
      }
    }
    std::cout << i << std::endl;
  }
  return 0;
}
Problem p01094 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n;
  while (cin >> n, n) {
    vector<char> c(n);
    for (int i = 0; i < n; i++)
      cin >> c[i];
    vector<int> box('Z' - 'A' + 1, 0);
    for (int i = 0; i < n; i++) {
      box[c[i] - 'A']++;
      int fir_b = -1;
      int index = -1;
      int sec_b = -1;
      for (int j = 0; j <= 'Z' - 'A'; j++) {
        int tmp = box[j];
        if (fir_b < box[j]) {
          tmp = fir_b;
          fir_b = box[j];
          index = j;
        }
        if (sec_b < tmp) {
          sec_b = tmp;
        }
      }
      if (fir_b > sec_b + (n - 1 - i)) {
        cout << char('A' + index) << " " << i + 1 << endl;
        break;
      }
      if (i == n - 1) {
        cout << "TIE" << endl;
      }
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int n;
  while (true) {
    cin >> n;
    if (n == 0)
      break;
    vector<int> c(n);
    for (int i = 0; i < n; i++)
      cin >> c[i];
    vector<int> box('z' - 'a' + 1, 0);
    for (int i = 0; i < n; i++) {
      box[c[i] - 'A']++;
      int max_b = -1;
      int sec_b = -1;
      int index = -1;
      for (int j = 0; j <= 'Z' - 'A'; j++) {
        int tmp;
        if (max_b < box[j]) {
          index = j;
          tmp = max_b;
          max_b = box[j];
        } else {
          tmp = box[j];
        }
        sec_b = max(sec_b, tmp);
      }
      if (max_b > sec_b + n - 1 - i) {
        cout << char(index + 'A') << endl;
        break;
      }
    }
  }
  return 0;
}
Problem p01095 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
const int lim = 7368791;

int main() {
  while (1) { // start

    bool a[lim + 1];
    memset(a, 0, sizeof(a));

    int m, n;
    cin >> m >> n;
    int idx = m;
    if (m == 0 and n == 0)
      break;

    // 敗因；全部なめた
    int cnt = 0;
    for (int i = m; cnt < n; i++) {
      if (a[i] == 0) {
        cnt++;
        for (int j = i; j <= lim; j += i) {
          a[j] = 1;
        }
      }
    }

    for (int i = m; i <= lim; i++) {
      if (a[i] == 0) {
        cout << i << endl;
        break;
      }
    }

  } // end

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const int lim = 8000000;

int main() {
  while (1) { // start

    int a[lim];
    for (int i = 0; i < lim; i++)
      a[i] = 0;

    int m, n;
    cin >> m >> n;
    int idx = m;
    if (m == 0 and n == 0)
      break;

    // 敗因；全部なめた
    /*
    for(int i = 0; i < n; i++){
            int flag = 0;
            for(int j = idx; j < lim; j++){
                    if(flag) break;
                    if(a[j] == 0){
                            idx = j;
                            flag = 1;
                            for(int k = idx; k <= lim; k += idx){
                                    if(k % j == 0) a[k] = 1;
                            }
                    }
            }
    }
    */

    int cnt = 0;
    for (int i = m; i < lim; i++) {
      if (a[i] == 0) {
        cnt++;
        for (int j = i; j < lim; j += i) {
          a[j] = 1;
        }
      }
      if (cnt == n)
        break;
    }

    for (int i = m; i < lim; i++) {
      if (a[i] == 0) {
        cout << i << endl;
        break;
      }
    }

  } // end

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

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

const int MAX = 7368791;

int sieveOfEratosthenes(int m, int n) {
  auto primes = vector<int>(MAX + 1, 0);
  for (int i = 2; i <= MAX; ++i)
    primes[i] = i;
  for (int i = m; i <= MAX; ++i) {
    if (primes[i]) {
      for (int j = i; j <= MAX; j += i)
        primes[j] = 0;
      if (!n)
        return i;
      --n;
    }
  }
  return -1;
}

int main() {
  int m, n;
  while (cin >> m >> n, m) {
    cout << sieveOfEratosthenes(m, n) << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

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

const int MAX = 7368791;

vector<int> sieveOfEratosthenes(int m, int n) {
  auto primes = vector<int>(MAX + 1, 0);
  for (int i = 2; i <= MAX; ++i)
    primes[i] = i;
  for (int i = m; i <= MAX && n > 0; ++i) {
    if (primes[i]) {
      for (int j = i; j <= MAX; j += i)
        primes[j] = 0;
      --n;
    }
  }
  primes.erase(remove(begin(primes), end(primes), 0), end(primes));
  return primes;
}

int main() {
  int m, n;
  while (cin >> m >> n, m) {
    auto p = sieveOfEratosthenes(m, n);
    cout << p[m - 2] << endl;
  }
  return 0;
}
Problem p01095 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

// ---------------------
// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                                               \\
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"                       \\
       << " " << __FILE__ << endl;

// ---------------------
#define INF 922337203685477580
#define IINF (1 << 21)
typedef long long ll;

int main() {
  while (1) {
    int m, n;
    cin >> m >> n;
    if (m == 0 && n == 0)
      break;

    // int furui[9000000];
    // bool furui[4000000];
    vector<bool> furui(7368792, true);
    // REP(i, 4000000 * 2) {
    //   furui[i] = true;
    // }

    int base = m;
    for (int trial = 0; trial < n; trial++) {
      for (int t = 1; t * base < 7368792; t++) {
        furui[base * t] = false;
      }
      while (furui[base] == false)
        base++;
    }

    FOR(i, m, 7368792) {
      if (furui[i] == true) {
        cout << i << endl;
        break;
      }
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

// ---------------------
// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                                               \\
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"                       \\
       << " " << __FILE__ << endl;

// ---------------------
#define INF 922337203685477580
#define IINF (1 << 21)
typedef long long ll;

int main() {
  while (1) {
    int m, n;
    cin >> m >> n;
    if (m == 0 && n == 0)
      break;

    // int furui[9000000];
    int furui[1000000];
    REP(i, 900000) { furui[i] = 1; }

    int base = m;
    for (int trial = 0; trial < n; trial++) {
      for (int t = 1; t * base < 900000; t++) {
        furui[base * t] = 0;
      }
      while (furui[base] == 0)
        base++;
    }

    FOR(i, m, 900000) {
      // debug(furui[i]);
      if (furui[i] == 1) {
        cout << i << endl;
        break;
      }
      cout << 7368791 << endl;
    }
  }

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

#include <iostream>

using namespace std;

constexpr int MAX_LEN = 7368791;

bool seeBamboo[MAX_LEN + 20] = {
    true,
    true,
};

int main() {
  int m, n;
  while (cin >> m >> n, (m + n)) {
    fill(seeBamboo + m, seeBamboo + MAX_LEN, false);

    int num = m;

    for (int i = 0; i < n; i++) {
      while (seeBamboo[num])
        num++;
      for (int j = num; j < MAX_LEN; j += num) {
        seeBamboo[j] = true;
      }
    }

    int ans = num;
    while (seeBamboo[ans])
      ans++;
    cout << ans << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

constexpr int MAX_LEN = 7368791;

bool seeBamboo[MAX_LEN + 20] = {
    true,
    true,
};

int main() {
  int m, n;
  while (cin >> m >> n, (m + n)) {
    fill(seeBamboo + m, seeBamboo + MAX_LEN, false);

    for (int i = 0; i < n; i++) {
      int num = m;
      while (seeBamboo[num])
        num++;
      for (int j = num; j < MAX_LEN; j += num) {
        seeBamboo[j] = true;
      }
    }

    int ans = m;
    while (seeBamboo[ans])
      ans++;
    cout << ans << endl;
  }

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

#include <bits/stdc++.h>
using namespace std;
#define M 7368800
int a[M];
int main() {
  int i, j, n, m;
  while (cin >> n >> m, n, m) {
    int c = 0;
    for (i = 0; i < M; i++)
      a[i] = 0;
    for (i = 0; i < n; i++)
      a[i]++;
    for (i = 0; i < m; i++) {
      while (a[c])
        c++;
      for (j = c; j < M; j += c)
        a[j]++;
    }
    for (; a[c]; c++) {
    }
    cout << c << endl;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int a[7368800];
int main() {
  int i, j, n, m;
  while (cin >> n >> m) {
    for (i = 0; i < 7368800; i++)
      a[i] = 0;
    int c = 0;
    for (i = 0; i < n; i++)
      a[i]++;
    for (i = 0; i < m; i++) {
      while (a[c])
        c++;
      for (j = c; j < 7368800; j += c)
        a[j]++;
    }
    for (; a[c]; c++) {
    }
    cout << c << endl;
  }
}