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

#include <bits/stdc++.h>

using namespace std;

bool e[7368792];

int main() {
  while (true) {
    int m, n;
    cin >> m >> n;
    if (m + n == 0) {
      break;
    }

    memset(e, false, sizeof(e));
    int count = 0;
    for (int i = m; count < n; i++) {
      if (!e[i]) {
        count++;
      } else {
        continue;
      }
      for (int j = 1; i * j < 7368792; j++) {
        e[i * j] = true;
      }
    }

    for (int i = m + 1;; i++) {
      if (!e[i]) {
        cout << i << endl;
        break;
      }
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

bool e[7368792];

int main() {
  while (true) {
    int m, n;
    cin >> m >> n;
    if (m + n == 0) {
      break;
    }

    memset(e, false, sizeof(e));
    int count = 0;
    for (int i = m; count < n; i++) {
      if (!e[i]) {
        count++;
      }
      for (int j = 1; i * j < 7368792; j++) {
        e[i * j] = true;
      }
    }

    for (int i = m + 1;; i++) {
      if (!e[i]) {
        cout << i << endl;
        break;
      }
    }
  }

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

#include <bits/stdc++.h>
using namespace std;
void solve(int m, int n) {
  vector<bool> v(7368791 - 2, true);
  int j, t = m;
  for (int i = 0; i < n; i++) {
    for (j = t; 1; j++) {
      if (v[j - 2])
        break;
    }
    for (t = j; t < 7368791; t += j) {
      v[t - 2] = false;
    }
    t = j;
  }
  for (int i = t; i <= 7368791; i++) {
    if (v[i - 2]) {
      cout << i << endl;
      return;
    }
  }
}

int main(void) {
  int m, n;
  while (cin >> m >> n, m) {
    solve(m, n);
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
void solve(int m, int n) {
  // cout<<"$$"<<endl;
  vector<int> v;
  int j;
  v.push_back(m);
  for (int i = 0; i < n; i++) {
    for (j = v.back() + 1; 1; j++) {
      bool s = true;
      // cout<<j<<endl;
      for (int x : v) {
        if (!(j % x)) {
          // cout<<"?"<<endl;
          s = false;
          break;
        }
      }
      if (s) {
        // cout<<"!"<<j<<endl;
        v.push_back(j);
        break;
      }
    }
    // cout<<"!"<<t<<endl;
    //     v.push_back(t);
  }
  cout << v.back() << endl;
  // cout<<endl;
  // for(int x:v){
  //             cout<<x<<" "<<endl;
  //         }
  //         cout<<endl;
  // cout << v.size();
}

int main(void) {
  int m, n;
  while (cin >> m >> n, m) {
    solve(m, n);
  }
}
Problem p01095 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
using namespace std;

int n, m;
bool used[7400000];

int main() {
  while (1) {
    scanf("%d%d", &m, &n);
    if (n == 0)
      break;
    int ans = m, counter = n;
    for (int i = 0; i < 7400000; i++)
      used[i] = false;
    while (1) {
      if (used[ans]) {
        ans++;
        continue;
      }
      for (int i = ans; i < 7400000; i += ans)
        used[i] = true;
      counter--;
      if (counter < 0)
        break;
      ans++;
    }
    printf("%d\\n", ans);
  }
}


Error: TLE

Fixed submission:

#include <cstdio>
using namespace std;

int n, m;

int main() {
  while (1) {
    scanf("%d%d", &m, &n);
    if (n == 0)
      break;
    int p[500000], pNum = 0;
    int i = m, j = n;
    for (; j >= 0; i++) {
      bool flag = false;
      for (int k = 0; k < pNum; k++) {
        if (i < p[k] * p[k])
          break;
        if (i % p[k] == 0) {
          flag = true;
          break;
        }
      }
      if (flag)
        continue;
      j--;
      p[pNum++] = i;
    }
    printf("%d\\n", i - 1);
  }
}
Problem p01095 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

#define reps(i, j, k) for (int i = j; i < k; i++)
#define rep(i, j) reps(i, 0, j)
#define fs first
#define sc second
#define mk make_pair

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;

const int M = 7400000;
int v[M];
int main() {
  int n, m;
  while (cin >> m >> n, m) {
    fill(v, v + M, 0);
    reps(i, m, M) {
      if (!v[i]) {
        for (int j = i + i; j < M; j += i)
          v[j] = 1;
        n--;
      }
      if (n < 0) {
        cout << i << endl;
        break;
      }
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

#define reps(i, j, k) for (int i = j; i < k; i++)
#define rep(i, j) reps(i, 0, j)
#define fs first
#define sc second
#define mk make_pair

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;

int main() {
  int n, m;
  while (cin >> m >> n, m) {
    int M = 10000000;
    vi v(M);
    reps(i, m, M) {
      if (!v[i]) {
        for (int j = i + i; j < M; j += i)
          v[j] = 1;
        n--;
      }
      if (n < 1) {
        cout << i << endl;
        break;
      }
    }
  }
  return 0;
}
Problem p01095 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define MAX_A 7368792
using namespace std;

int n, m;
bool a[MAX_A];
/*
int prime(int t) {
        int p=t;
    while(1) {
        bool f=true;
        for(int i=2;i<p;i++) {
                if(p%i==0) {
                        f=false;
                        break;
                }
        }
        if(f)return p;
        p++;
    }
}
*/
int main() {
  while (cin >> m >> n, n | m) {
    rep(i, MAX_A) a[i] = true;
    int c = 0, k = m;
    while (c < n) {
      if (a[k]) {
        for (int j = k; j < MAX_A; j += k) {
          a[j] = false;
        }
        c++;
      }
      k++;
    }
    bool f = false;
    rep(i, MAX_A) {
      if (f && a[i]) {
        cout << i << endl;
        break;
      } else if (!f && !a[i])
        f = !f;
    }
  }
  return 0;
}

Error: -11

Fixed submission:

#include <iostream>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define MAX_A 7368792
using namespace std;

int n, m;
bool a[MAX_A];

int prime(int t) {
  int p = t;
  while (1) {
    bool f = true;
    for (int i = 2; i < p; i++) {
      if (p % i == 0) {
        f = false;
        break;
      }
    }
    if (f)
      return p;
    p++;
  }
}

int main() {
  while (cin >> m >> n, n | m) {
    rep(i, MAX_A) a[i] = true;
    int c = 0, k = prime(m) - 1;
    while (c < n) {
      if (a[k]) {
        for (int j = k; j < MAX_A; j += k) {
          a[j] = false;
        }
        c++;
      }
      k++;
    }
    bool f = false;
    rep(i, MAX_A) {
      if (f && a[i]) {
        cout << i << endl;
        break;
      } else if (!f && !a[i])
        f = !f;
    }
  }
  return 0;
}
Problem p01095 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>
#include <stdlib.h>
// #include<time.h>

int main() {
  int m, n, flag;
  int year, count_bamboo, bamboo[500000];
  char *Year;
  // clock_t start, end;
  Year = (char *)malloc(sizeof(char) * 7368791);
  while (1) {
    scanf("%d %d", &m, &n);
    if (m == 0 && n == 0)
      break;

    // start = clock();
    // mとnの関係で判断
    //  1 m>=n の時 m+n年
    //  2 m<n の時 埋められなくなる年をカウントしてそれがnを超える年
    //  2 m<n の時 埋められなくなる年をカウントしてそれがnを超える年
    // 素数探すのに似とる//エラトステネスの篩
    if (m < n) {
      for (int i = 1; i < 7368791; i++)
        Year[i] = '0'; // 2から7368791まで初期化
      count_bamboo = 0;
      for (year = m; year < 7368791;) {
        count_bamboo++;
        if (count_bamboo > n)
          break;
        for (int i = year - 1; i < 7368791; i += year) // yearの倍数埋める
          Year[i] = '1';
        for (int i = year;; i++) // 埋まってないとこ探す
          if (Year[i] == '0') {
            year = i;
            Year[year] = '1';
            year++;
            break;
          }
      }
      printf("%d\\n", year);
    } else
      printf("%d\\n", m + n);
    // end = clock();
    // printf("%.2f秒かかりました\\n", (double)(end - start) / CLOCKS_PER_SEC);
  }
  free(Year);
  return 0;
}


Error: TLE

Fixed submission:

#include <stdio.h>
#include <time.h>
int main() {
  int m, n, flag;
  int year, count_bamboo, bamboo[500000];

  clock_t start, end;

  while (1) {

    scanf("%d %d", &m, &n);
    if (m == 0 && n == 0)
      break;
    // start = clock();
    // mとnの関係で判断
    //  1 m>=n の時 m+n年
    //  2 m<n の時
    //  2*m+1年以降で埋められなくなる年をカウントしてそれがnを超える年

    // 2 m<n の時2* m+1年以降で埋められなくなる年をカウントしてそれがnを超える年
    // 素数探すのに似とる
    if (m < n) {
      count_bamboo = m;
      for (int i = 0; i < m; i++)
        bamboo[i] = i + m;
      for (year = 2 * m + 1; count_bamboo <= n; year += 2) {
        flag = 1;
        for (int i = 0;; i++) {
          // printf("%d\\n",year);
          // これやと遅い
          if (bamboo[i] > year / 2)
            break;
          if (year % bamboo[i] == 0) {
            flag = 0;
            break;
          }
        }
        if (flag) // 今までのモノで埋められなかった
        {
          bamboo[count_bamboo] = year;
          count_bamboo++;
        }
      }
      // for (int i = 0; i < count_bamboo; i++)printf("%3d", i+1);
      // putchar('\\n');
      // for (int i = 0; i < count_bamboo;i++)printf("%3d",bamboo[i]);
      // putchar('\\n');
      printf("%d\\n", year - 2);

    } else
      printf("%d\\n", m + n);
    // end = clock();
    // printf("%.2f秒かかりました\\n", (double)(end - start) / CLOCKS_PER_SEC);
  }
  return 0;
}
/*
3 1
3 4
10 20
100 50
2 50000
*/
Problem p01095 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
bool ok[7368792];
int main() {
  int m, n;
  while (scanf("%d%d", &m, &n), m) {
    memset(ok, 0, sizeof(ok));
    int cnt = 0;
    for (int i = m;; i++) {
      if (ok[i])
        continue;
      if (++cnt > n) {
        printf("%d\\n", i);
        break;
      }
      for (int j = i; j <= 7368791; j += i)
        ok[j] = true;
    }
  }
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
bool ok[7368792];
int main() {
  int m, n;
  while (scanf("%d%d", &m, &n), m) {
    memset(ok, 0, sizeof(ok));
    int cnt = 0;
    for (int i = m;; i++) {
      if (!ok[i])
        continue;
      if (++cnt > n) {
        printf("%d\\n", i);
        break;
      }
      for (int j = i; j <= 7368791; j += i)
        ok[j] = true;
    }
  }
}
Problem p01095 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;

bool ok[7368792];
int main() {
  int m, n;
  while (scanf("%d%d", &m, &n), m) {
    memset(ok, 0, sizeof(ok));
    int cnt = 0;
    for (int i = m;; i++) {
      if (!ok[i]) {
        if (++cnt > n) {
          printf("%d\\n", i);
          break;
        }
        for (int j = i; j <= 7368791; j += i)
          ok[j] = true;
      }
    }
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;

bool ok[7368793];
int main() {
  int m, n;
  while (scanf("%d%d", &m, &n), m) {
    memset(ok, 0, sizeof(ok));
    int cnt = 0;
    for (int i = m;; i++) {
      if (!ok[i]) {
        if (++cnt > n) {
          printf("%d\\n", i);
          break;
        }
        int ans = -1;
        for (int j = 1; j * j <= i; j++) {
          if (i % j == 0) {
            if (j >= m) {
              ans = j;
              break;
            }
            if (i / j >= m) {
              if (~ans && ans <= i / j)
                break;
              ans = i / j;
            }
          }
        }
        if (!~ans) {
          printf("%d\\n", i);
          break;
        }
        for (int j = i; j <= 7368791; j += ans)
          ok[j] = true;
      }
    }
  }
}
Problem p01095 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i, n) for (i = 0; i < n; i++)
#define loop(i, a, n) for (i = a; i < n; i++)
#define all(in) in.begin(), in.end()
#define shosu(x) fixed << setprecision(x)

typedef vector<int> vi;
typedef pair<int, int> pii;

int main(void) {
  int i, j, k;
  int n, m;
  while (1) {
    cin >> n >> m;
    if (n == 0 && m == 0)
      break;
    int tmp = 8000000;
    vector<bool> prime(tmp);
    int t = 0;
    for (i = n; i < tmp; i++)
      if (prime[i] == 0) {
        t++;
        if (t == m + 1)
          break;
        for (j = 1; i * j < tmp; j++)
          prime[i * j] = true;
      }
    cout << i << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i, n) for (i = 0; i < n; i++)
#define loop(i, a, n) for (i = a; i < n; i++)
#define all(in) in.begin(), in.end()
#define shosu(x) fixed << setprecision(x)

typedef vector<int> vi;
typedef pair<int, int> pii;

int main(void) {
  int i, j, k;
  int n, m;
  while (1) {
    cin >> n >> m;
    if (n == 0 && m == 0)
      break;
    int tmp = 8000000;
    vi prime(tmp);
    int t = 0;
    for (i = n; i < tmp; i++)
      if (prime[i] == 0) {
        t++;
        if (t == m + 1)
          break;
        for (j = 1; i * j < tmp; j++)
          prime[i * j]++;
      }
    cout << i << endl;
  }
}
Problem p01095 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(), in.end()
#define shosu(x) fixed << setprecision(x)
using namespace std;
// kaewasuretyuui
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef pair<int, pii> pip;
typedef vector<pip> vip;
const double PI = acos(-1);
const double EPS = 1e-8;
const int inf = 1e8;
int main() {
  int n, m;
  while (cin >> n >> m, n + m) {
    vi in(7368792);
    int t = n;
    while (m--) {
      while (in[t])
        t++;
      for (int i = t; i < 7368792; i += t)
        in[i] = true;
    }
    while (in[t])
      t++;
    cout << t << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(), in.end()
#define shosu(x) fixed << setprecision(x)
using namespace std;
// kaewasuretyuui
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef pair<int, pii> pip;
typedef vector<pip> vip;
const double PI = acos(-1);
const double EPS = 1e-8;
const int inf = 1e8;
int in[8000000];
int main() {
  int n, m;
  while (cin >> n >> m, n + m) {
    fill(in, in + 8000000, false);
    int t = n;
    while (m--) {
      while (in[t])
        t++;
      for (int i = t; i < 8000000; i += t)
        in[i] = true;
    }
    while (in[t])
      t++;
    cout << t << endl;
  }
}
Problem p01095 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;
int MAX = 7368791;
int main() {
  int n, m;
  bool f[MAX + 1];
  while (1) {
    cin >> m >> n;
    if (m + n == 0)
      break;
    REP(i, MAX + 1) f[i] = false;
    for (int i = m;; i++) {
      if (!f[i]) {
        if (n == 0) {
          cout << i << endl;
          break;
        } else {
          n--;
          for (int j = i; j <= MAX; j += i) {
            f[j] = true;
          }
        }
      }
    }
  }
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;
int MAX = 736891;
int main() {
  int n, m;
  bool f[MAX + 1];
  while (1) {
    cin >> m >> n;
    if (m + n == 0)
      break;
    REP(i, MAX + 1) f[i] = false;
    for (int i = m;; i++) {
      if (!f[i]) {
        if (n == 0) {
          cout << i << endl;
          break;
        } else {
          n--;
          for (int j = i; j <= MAX; j += i) {
            f[j] = true;
          }
        }
      }
    }
  }
}
Problem p01095 (C++) — buggy submission, verdict: Time Limit Exceeded

#include "bits/stdc++.h"
#include <unordered_map>
#include <unordered_set>
#pragma warning(disable : 4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\\d_download\\visual studio
///2015\\projects\\programing_contest_c++\\debug\\a.txt" > "d:\\d_download\\visual
///studio 2015\\projects\\programing_contest_c++\\debug\\b.txt"

int main() {
  while (1) {
    int M, N;
    cin >> M >> N;
    if (!M)
      break;
    vector<int> oks(7368793);
    int used = 0;
    int ans = -1;
    for (int i = M; i < 1e7; ++i) {
      if (!oks[i]) {
        if (used == N) {
          ans = i;
          break;
        }
        for (int j = i; j < 7368793; j += i) {
          oks[j] = true;
        }
        used++;
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include "bits/stdc++.h"
#include <unordered_map>
#include <unordered_set>
#pragma warning(disable : 4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\\d_download\\visual studio
///2015\\projects\\programing_contest_c++\\debug\\a.txt" > "d:\\d_download\\visual
///studio 2015\\projects\\programing_contest_c++\\debug\\b.txt"

int main() {
  while (1) {
    int M, N;
    cin >> M >> N;
    if (!M)
      break;
    vector<int> oks(1e7);
    int used = 0;
    int ans = -1;
    for (int i = M; i < 1e7; ++i) {
      if (!oks[i]) {
        if (used == N) {
          ans = i;
          break;
        }
        for (int j = i; j < 1e7; j += i) {
          oks[j] = true;
        }
        used++;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p01095 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int m, n;
  while (cin >> m >> n, m) {
    vector<int> goodyear(7368792, 0);
    int cnt = 0;
    int res = -1;
    for (int i = m;; i++) {
      if (goodyear[i] == 0) {
        if (cnt == n) {
          res = i;
          break;
        } else {
          cnt++;
          for (int j = i; j < 7368792; j += i) {
            goodyear[j] = 1;
          }
        }
      }
    }
    cout << res << endl;
  }
}

Error: -11

Fixed submission:

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

int main() {
  int m, n;
  while (cin >> m >> n, m) {
    vector<int> goodyear(7368792, 0);
    int cnt = 0;
    int res = -1;
    for (int i = m;; i++) {
      if (goodyear[i] == 0) {
        if (cnt == n) {
          res = i;
          break;
        } else {
          cnt++;
          for (int j = i; j < 1e7; j += i) {
            goodyear[j] = 1;
          }
        }
      }
    }
    cout << res << endl;
  }
}
Problem p01095 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>

using namespace std;

int n, m;
#define MAX 7368792
#define NUM 5

int main() {
  while (true) {
    cin >> m >> n;
    if (n <= 0)
      break;
    int arr[MAX]{};
    int count = 0;
    vector<int> prms;
    for (int i = m; i < MAX; i++) {
      m = i;
      bool flag = arr[i] == 0;
      if (flag) {
        for (int prm : prms)
          flag &= m % prm != 0;
        if (flag) {
          if (count >= n)
            break;
          count++;
          if (prms.size() <= NUM) {
            prms.push_back(m);
          } else {
            for (int j = 1; j * m < MAX; j++) {
              arr[j * m] = 1;
            }
          }
          m++;
        }
      }
    }
    cout << m << endl;
  }
}


Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int n, m;
#define MAX 7368791

int main() {
  while (true) {
    cin >> m >> n;
    if (n <= 0)
      break;
    int arr[MAX]{};
    int count = 0;
    int last_i = 0;
    for (int i = m; i < MAX; i++) {
      last_i = i;
      if (arr[i] == 0) {
        // cout << i << "," << m << "," << count << endl;
        if (count >= n)
          break;
        count++;
        // arr[i] = 1;
        for (int j = 1; j * m < MAX; j++) {
          arr[j * m] = 1;
        }
        m++;
      }
    }
    // for(int i = 0; i <= m; i++) cout << arr[i] << " ";
    // cout << endl;
    cout << last_i << endl;
  }
}
Problem p01095 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
typedef long long ll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define rep(i, m, n) for (int i = (m); i < (n); i++)
#define P pair<int, int>
#define pb push_back
#define mk make_pair
using namespace std;
#define Vec(a) vector<int> a
const int INF = 1 << 20;
const int MOD = 1e9 + 7;

int main() {
  // cout << "!" << endl;
  int n, m;
  while (cin >> m >> n, n) {
    // cout << "!" << endl;
    vector<int> a;
    bool c[7368792] = {0};
    for (int i = m; i < 7368792; i++) {
      if (!c[i]) {
        a.pb(i);
        if (a.size() == n + 1) {
          break;
        }
        for (int j = i; j < 7368792; j = j + i) {
          c[j] = true;
        }
      }
    }
    /*
    REP(i,100){
      cout << a[i] << endl;
      }*/
    cout << a[n] << endl;
  }
  return 0;
}


Error: -11

Fixed submission:

#include <bits/stdc++.h>
typedef long long ll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define rep(i, m, n) for (int i = (m); i < (n); i++)
#define P pair<int, int>
#define pb push_back
#define mk make_pair
using namespace std;
#define Vec(a) vector<int> a
const int INF = 1 << 20;
const int MOD = 1e9 + 7;

int main() {
  // cout << "!" << endl;
  int n, m;
  while (cin >> m >> n, n) {
    // cout << "!" << endl;
    vector<int> a;
    bool c[7368792] = {0};
    for (int i = m; i < sqrt(7368792) + 1; i++) {
      if (!c[i]) {
        a.pb(i);
        for (int j = i; j < 7368792; j = j + i) {
          c[j] = 1;
        }
      }
    }
    /*
    REP(i,100){
      cout << a[i] << endl;
      }*/
    cout << a[n] << endl;
  }
  return 0;
}
Problem p01095 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;

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

int m, n;
int prime[7700001];

int main(void) {
  while (1) {
    scanf("%d%d", &m, &n);
    if (m == 0 && n == 0)
      break;
    memset(prime, true, sizeof(prime));
    int cnt = 0;
    prime[0] = false;
    prime[1] = false;
    for (int i = m; i <= 7700000; i++) {
      if (cnt == n)
        break;
      if (prime[i]) {
        cnt++;
        for (int j = i; j <= 7700000; j += i) {
          prime[j] = false;
        }
      }
    }
    int res = m + n;
    while (!prime[res])
      res++;
    printf("%d\\n", res);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;

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

int m, n;
int prime[8000001];

int main(void) {
  while (1) {
    scanf("%d%d", &m, &n);
    if (m == 0 && n == 0)
      break;
    memset(prime, true, sizeof(prime));
    int cnt = 0;
    prime[0] = false;
    prime[1] = false;
    for (int i = m; i <= 8000000; i++) {
      if (cnt == n)
        break;
      if (prime[i]) {
        cnt++;
        for (int j = i; j <= 8000000; j += i) {
          prime[j] = false;
        }
      }
    }
    int res = m + n;
    while (!prime[res])
      res++;
    printf("%d\\n", res);
  }
  return 0;
}