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

// #include<bits/stdc++.h>
#include <climits>
#include <cstring>
#include <iostream>

using namespace std;

const int MAX = 7368791;

int main() {
  int m, n;
  while (cin >> m >> n, m | n) {
    bool isntprime[MAX + 1];
    memset(isntprime, false, sizeof isntprime);
    // fill(isntprime,isntprime+MAX,false);
    // era(m,n);
    for (int i = m;; ++i) {
      if (!isntprime[i]) {
        if (n)
          --n;
        else {
          cout << i << endl;
          break;
        }
        for (int j = i; j <= MAX; j += i)
          isntprime[j] = true;
      }
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

// #include<bits/stdc++.h>
#include <climits>
#include <cstring>
#include <iostream>

#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)

using namespace std;

typedef long long ll;

const ll MAX = 7368791;

int main() {
  int m, n;
  while (cin >> m >> n, m | n) {
    bool isntprime[MAX + 1];
    memset(isntprime, false, sizeof isntprime);
    // fill(isntprime,isntprime+MAX,false);
    // era(m,n);
    for (int i = m;; ++i) {
      if (!isntprime[i]) {
        if (n)
          --n;
        else {
          cout << i << endl;
          break;
        }
      }
      for (int j = i; j <= MAX; j += i) {
        isntprime[j] = true;
      }
    }
  }
  return 0;
}
Problem p01095 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int prime[N] = {0};
int n, m, now = 0;

int sprime() {
  int i, j;
  for (i = n; i < N; ++i)
    if (prime[i] == 0) {
      if (now == m)
        return i;
      ++now;
      for (j = 1; i * j < min(N, m * 1000); ++j)
        prime[i * j] = 1;
    }
  return 0;
}

int main() {
  while (1) {
    memset(prime, 0, sizeof(prime));
    cin >> n >> m;
    now = 0;
    if (n + m == 0)
      break;
    cout << sprime() << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

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

int prime[N] = {0};
int n, m, now = 0;

int sprime() {
  int i, j;
  for (i = n; i < N; ++i)
    if (prime[i] == 0) {
      if (now == m)
        return i;
      ++now;
      for (j = 1; i * j < N; ++j)
        prime[i * j] = 1;
    }
  return 0;
}

int main() {
  while (1) {
    memset(prime, 0, sizeof(prime));
    cin >> n >> m;
    now = 0;
    if (n + m == 0)
      break;
    cout << sprime() << endl;
  }
  return 0;
}
Problem p01095 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

const int limit = 7369791;

int M, N;
int dp[limit + 1];

int main() {
  memset(dp, -1, sizeof(dp));
  int a = 0;
  while (cin >> M >> N, M) {
    for (int i = M; i <= limit; i++) {
      if (dp[i] != a) {
        if (--N < 0) {
          cout << i << endl;
          break;
        }
        for (int j = i + i; j <= limit; j += i)
          dp[j] = a;
      }
    }
    ++a;
  }
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

const int limit = 7369791;

int main() {
  int M, N;
  int dp[limit + 1];
  memset(dp, -1, sizeof(dp));
  int a = 0;
  while (cin >> M >> N, M) {
    for (int i = M; i <= limit; i++) {
      if (dp[i] != a) {
        if (--N < 0) {
          cout << i << endl;
          break;
        }
        for (int j = i + i; j <= limit; j += i)
          dp[j] = a;
      }
    }
    ++a;
  }
}
Problem p01095 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>

using namespace std;

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

bool memo[8000000];
int m, n;

void furui(int n, int count) {
  fill(memo, memo + 8000000, true);

  int cnt = 0;
  for (int i = m; i <= m + n; i++) {
    if (memo[i - m]) {
      memo[i - m] = false;
      for (int j = 2 * i; j <= n; j += i) {
        memo[j - m] = false;
      }
      cnt++;
      break;
      if (cnt == count)
        return;
    }
  }
  return;
}

int main() {
  while (cin >> m >> n) {
    if (m == 0 && n == 0)
      return 0;
    fill(memo, memo + 8000000, true);

    int l = m;
    for (int k = 0; k < n; k++) {
      for (int i = l; i <= 8000000; i++) {
        if (memo[i - m]) {
          l = i;
          memo[i - m] = false;
          for (int j = ((m + i - 1) / i) * i; j <= 8000000; j += i) {
            memo[j - m] = false;
          }
          break;
        }
      }
      /*
      for(int i=m;i<=13;i++){
              cout<<i<<" memo[i-m]:"<<memo[i-m]<<" ";
      }
      cout<<endl;
      */
    }
    for (int i = 0; i <= 8000000; i++) {
      if (memo[i]) {
        cout << i + m << endl;
        break;
      }
    }
  }

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>

using namespace std;

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

bool memo[8000000];
int m, n;

void furui(int n, int count) {
  fill(memo, memo + 8000000, true);

  int cnt = 0;
  for (int i = m; i <= m + n; i++) {
    if (memo[i - m]) {
      memo[i - m] = false;
      for (int j = 2 * i; j <= n; j += i) {
        memo[j - m] = false;
      }
      cnt++;
      break;
      if (cnt == count)
        return;
    }
  }
  return;
}

int main() {
  while (cin >> m >> n) {
    if (m == 0 && n == 0)
      return 0;
    fill(memo, memo + 8000000, true);

    int l = m;
    for (int k = 0; k < n; k++) {
      for (int i = l; i <= 8000000; i++) {
        if (memo[i - m]) {
          l = i;
          memo[i - m] = false;
          for (int j = ((m - i + 1) / i) * i; j <= 8000000; j += i) {
            memo[j - m] = false;
          }
          break;
        }
      }
      /*
      for(int i=m;i<=13;i++){
              cout<<i<<" memo[i-m]:"<<memo[i-m]<<" ";
      }
      cout<<endl;
      */
    }
    for (int i = 0; i <= 8000000; i++) {
      if (memo[i]) {
        cout << i + m << endl;
        break;
      }
    }
  }

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

#include <algorithm>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int a[10000000] = {};
int main() {
  const long long int mod = 1000000007;
  map<long long int, long long int> mp;
  // cout << fixed << setprecision(10);
  long long int n, m, b, c, d, k, sa, h, w, left = 1, right = 0;
  long long int sc, sr, num2, no[1005][1005] = {}, res = 999999999, count = 0,
                              now = 0, mi = 9999999999;

  string str, t;

  cin >> m >> n;
  while (1) {
    res = 0;
    count = n;
    now = m;
    if (m == 0 && n == 0) {
      return 0;
    }
    while (1) {
      if (count == 0 && a[now] == 0) {
        cout << now << endl;
        for (int i = 2; i < 7500000; i++) {
          a[i] = 0;
        }
        break;
      }
      if (a[now] == 0) {
        for (int i = 2; i * now < 7500000; i++) {
          a[i * now] = 1;
        }
        count--;
      }
      now++;
    }
    cin >> m >> n;
  }
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
long long int a[10000000] = {};
int main() {
  const long long int mod = 1000000007;
  map<long long int, long long int> mp;
  // cout << fixed << setprecision(10);
  long long int n, m, b, c, d, k, sa, h, w, left = 1, right = 0;
  long long int sc, sr, num2, no[1005][1005] = {}, res = 999999999, count = 0,
                              now = 0, mi = 9999999999;

  string str, t;

  cin >> m >> n;
  while (1) {
    res = 0;
    count = n;
    now = m;
    if (m == 0 && n == 0) {
      return 0;
    }
    while (1) {
      if (count == 0 && a[now] == 0) {
        cout << now << endl;
        for (int i = 2; i < 7500000; i++) {
          a[i] = 0;
        }
        break;
      }
      if (a[now] == 0) {
        for (int i = 2; i * now < 7500000; i++) {
          a[i * now] = 1;
        }
        count--;
      }
      now++;
    }
    cin >> m >> n;
  }
}
Problem p01095 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <iostream>
#include <vector>

using namespace std;
#define NUM 7368792

int main() {

  int m, n;
  char *data;
  data = new char[NUM];
  int cnt = 0;

  while (cin >> m >> n) {
    if (m == 0 && n == 0)
      break;
    for (int i = 0; i < NUM; i++) {
      data[i] = 0;
    }
    cnt = 0;
    for (int i = m; cnt < n; i++) {
      if (data[i] == 1) {
        continue;
      }
      for (int j = i; j < NUM; j += i) {
        data[j] = 1;
      }
      cnt++;
    }
    for (int i = 0; i < NUM; i++) {
      // cout<<data[i]<<endl;
      if (data[i] == 0 && i > m) {
        cout << i << endl;
        break;
      }
    }
  }

  return 0;
}

Error: MLE

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;
#define NUM 7368792

int main() {

  int m, n;
  bool *data;
  data = new bool[NUM];
  int cnt = 0;

  while (cin >> m >> n) {
    if (m == 0 && n == 0)
      break;
    data = new bool[NUM];
    cnt = 0;
    for (int i = m; cnt < n; i++) {
      if (data[i] == 1) {
        continue;
      }
      for (int j = i; j < NUM; j += i) {
        data[j] = 1;
      }
      cnt++;
    }
    for (int i = 0; i < NUM; i++) {
      // cout<<data[i]<<endl;
      if (data[i] == 0 && i > m) {
        cout << i << endl;
        break;
      }
    }
  }

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

#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <string>
#include <utility>
#include <vector>
#define INF 2147483647
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ll long long

using namespace std;
int main() {
  int m, n;

  while (cin >> m >> n, m + n) {
    int cnt = 0;
    int now = m;
    bool flag[7368800] = {};
    while (cnt != n) {
      while (flag[now])
        now++;
      for (int i = now; i < 7368792; i += now)
        flag[i] = true;
      cnt++;
    }
    for (int i = now;; i++)
      if (flag[i] == false) {
        cout << i << endl;
        break;
      }
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <string>
#include <utility>
#include <vector>
#define INF 2147483647
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ll long long

using namespace std;
int main() {
  int m, n;
  int cnt = 0;
  int now = m;
  while (cin >> m >> n, m + n) {
    bool flag[7368800] = {};
    while (cnt != n) {
      while (flag[now])
        now++;
      for (int i = now; i < 7368792; i += now)
        flag[i] = true;
      cnt++;
    }
    for (int i = now;; i++)
      if (flag[i] == false) {
        cout << i << endl;
        break;
      }
  }
  return 0;
}
Problem p01095 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define MAX_K 7500000
int SIZE = 7500000;
bool f[MAX_K];
int M, N;
int main() {
  while (true) {
    f[0] = 1;
    f[1] = 1;
    for (int i = 2; i < 7500000; i++) {
      f[i] = 0;
    }
    scanf("%d%d", &M, &N);
    if (M == 0 && N == 0) {
      break;
    }
    while (true) {
      if (!f[M]) {
        N--;
        if (N < 0) {
          break;
        }
        for (int j = 1; M * j < SIZE; j++) {
          if (!f[M * j]) {
            f[M * j] = true;
          }
        }
      }
      M++;
    }
    printf("%d\\n", M);
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define MAX_K 10000000
bool f[MAX_K];

int main() {
  while (true) {
    for (int i = 0; i < 10000000; i++) {
      f[i] = 0;
    }
    int M, N;
    scanf("%d%d", &M, &N);
    if (M == 0 && N == 0) {
      break;
    }
    int N_ = N;
    int ans = M;
    do {
      bool F = false;
      for (int i = 2; i * i <= ans; i++) {
        if (ans % i == 0) {
          if (f[i] || f[ans / i]) {
            F = true;
            break;
          }
        }
      }
      if (F) {
        ans++;
        continue;
      }
      N_--;
      f[ans++] = true;
    } while (N_ >= 0);
    printf("%d\\n", ans - 1);
  }
  return 0;
}
Problem p01095 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  while (1) {
    int m, n;
    cin >> m >> n;
    if (n == 0 && m == 0)
      break;
    vector<bool> so(7368792, true);
    int i;
    int ans = 0;
    for (i = m; i < 7368792; i++) {
      if (so[i]) {
        for (int j = i * 2; j < 7368792; j += i)
          so[j] = false;
        ans++;
        // cout<<i<<endl;
      }
      if (ans > n)
        break;
    }
    cout << i << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  while (1) {
    int m, n;
    cin >> m >> n;
    if (n == 0 && m == 0)
      break;
    int i;
    vector<int> use;
    use.push_back(m);
    for (i = m + 1; i < 7368792; i++) {
      int k = 1;
      for (int j = 0; j < use.size(); j++) {
        if (i % use[j] == 0) {
          //          cout<<i<<endl;
          //          use.push_back(i);
          k = 0;
          break;
        }
      }
      // cout<<i<<endl;
      if (k == 1)
        use.push_back(i);
      if (use.size() == n + 1)
        break;
    }
    cout << i << endl;
    // cout<<endl;
    // for(int i=0;i<m;i++)cout<<use[i]<<endl;
  }
  return 0;
}
Problem p01095 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int dp[10000000], n, m, r[10000000];
int main() {
  while (true) {
    cin >> n >> m;
    if (n == 0 && m == 0)
      break;
    for (int i = 0; i < 5000000 + 5 * m; i++)
      dp[i] = 0;
    for (int i = 0; i < 5000000 + 5 * m; i++)
      r[i] = i;
    for (int i = n; i < 2750; i++) {
      for (int j = i; j * j < 5000000 + 5 * m; j += i) {
        if (r[j] == 0)
          r[j] = i;
      }
    }
    int c = n;
    for (int i = 0; i < m; i++) {
      while (dp[c] == 1)
        c++;
      for (int j = c; j < 5000000 + 5 * m; j += r[c])
        dp[j] = 1;
    }
    while (dp[c] == 1)
      c++;
    cout << c << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int dp[10000000], n, m, r[10000000];
int main() {
  while (true) {
    cin >> n >> m;
    if (n == 0 && m == 0)
      break;
    for (int i = 0; i < 7400000; i++)
      dp[i] = 0;
    for (int i = 0; i < 7400000; i++)
      r[i] = i;
    for (int i = n; i < 2750; i++) {
      for (int j = i; j * j < 7400000; j += i) {
        if (r[j] == 0)
          r[j] = i;
      }
    }
    int c = n;
    for (int i = 0; i < m; i++) {
      while (dp[c] == 1)
        c++;
      for (int j = c; j < 7400000; j += r[c])
        dp[j] = 1;
    }
    while (dp[c] == 1)
      c++;
    cout << c << endl;
  }
  return 0;
}
Problem p01095 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;
#define N 7500000

bool years[N + 10];

int main() {
  int m, n;
  while (cin >> m >> n) {
    if (m == 0 && n == 0) {
      break;
    }
    for (int i = m; i <= N; i++) {
      years[i] = true;
    }

    for (int i = m; i <= N; i++) {
      if (years[i]) {
        if (n == 0) {
          cout << i << endl;
          break;
        }
        n--;

        for (int j = i + i; j <= N; j += i) {
          years[j] = false;
        }
      }
    }
  }
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;
#define N 7500000

int years[N + 10];

int main() {
  int m, n;
  while (cin >> m >> n) {
    if (m == 0 && n == 0) {
      break;
    }
    for (int i = m; i <= N; i++) {
      years[i] = 1;
    }

    for (int i = m; i <= N; i++) {
      if (years[i]) {
        if (n == 0) {
          cout << i << endl;
          break;
        }
        n--;

        for (int j = i + i; j <= N; j += i) {
          years[j] = 0;
        }
      }
    }
  }
}
Problem p01095 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 7.4 * 1e6;
int primes[MAX_N + 1]; // i????´???°??????true

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

  while (true) {
    int m, n;
    cin >> m >> n;
    if (m == 0 && n == 0)
      break;
    for (int i = 0; i < MAX_N; i++)
      primes[i] = true;
    int count = 0;
    primes[0] = primes[1] = false;
    for (int i = m; i <= MAX_N; i++) {
      if (primes[i]) {
        for (int j = 2 * i; j <= MAX_N; j += i)
          primes[j] = false;
        count++;
        if (count > n) {
          cout << i << endl;
          break;
        }
      }
    }
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 1e7;
int primes[MAX_N + 1]; // i????´???°??????true

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

  while (true) {
    int m, n;
    cin >> m >> n;
    if (m == 0 && n == 0)
      break;
    for (int i = 0; i < MAX_N; i++)
      primes[i] = true;
    int count = 0;
    primes[0] = primes[1] = false;
    for (int i = m; i <= MAX_N; i++) {
      if (primes[i]) {
        for (int j = 2 * i; j <= MAX_N; j += i)
          primes[j] = false;
        count++;
        if (count > n) {
          cout << i << endl;
          break;
        }
      }
    }
  }
}
Problem p01095 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bitset>
#include <iostream>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define REP(i, n) for (long i = 0; i < n; i++)
#define FOR(i, m, n) for (long i = m; i < n; i++)

using namespace std;

int main(void) {
  long m, n;
  while (1) {
    cin >> m >> n;
    if (m == 0 && n == 0)
      break;
    bitset<7368792> a(0);
    long lim = 7368792;
    long ans;
    FOR(i, m, lim) {
      if (!a[i]) {
        if (n == 0) {
          ans = i;
          break;
        }
        n--;
        long val = i;
        for (int j = 1; j * val < lim; j++) {
          a.set(j * val);
        }
      }
    }
    cout << ans << endl;
  }
}


Error: TLE

Fixed submission:

#include <iostream>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define REP(i, n) for (long i = 0; i < n; i++)
#define FOR(i, m, n) for (long i = m; i < n; i++)

using namespace std;

int main(void) {
  long m, n;
  while (1) {
    cin >> m >> n;
    if (m == 0 && n == 0)
      break;
    vector<long> a(7368792, 0);
    long lim = 7368792;
    long ans;
    FOR(i, m, lim) {
      if (!a[i]) {
        if (n == 0) {
          ans = i;
          break;
        }
        n--;
        long val = i;
        for (int j = 1; j * val < lim; j++) {
          a[j * val] = 1;
        }
      }
    }
    cout << ans << endl;
  }
}
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) {
    bool s[7654321] = {};
    int i = m, j = 0, k;
    for (; j <= n; i++)
      if (!s[i])
        for (k = 2, j++; i * k < 7654321; k++)
          s[i * k] = 1;
    cout << i - 1 << endl;
  }
  return 0;
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int m, n;
  while (cin >> m >> n, m) {
    bool s[7654321] = {};
    int i = m, j = 0, k;
    for (; j <= n; i++)
      if (!s[i] && j != n)
        for (k = 2, j++; i * k < 7654321; k++)
          s[i * k] = 1;
    cout << i - 1 << endl;
  }
  return 0;
}
Problem p01095 (C++) — buggy submission, verdict: Time Limit Exceeded

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

//??¨??????????????????????????£??????
#define MAX 7500000

int main() {

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

    vector<bool> p(MAX, false);
    int j = m;
    int ans;
    while (n > 0) {
      if (p[j] == false) {
        ans = j;
        for (int k = j; k < MAX; k += j) {
          p[k] = true;
        }
        n--;
      }
      j++;
    }

    while (1) {
      if (p[ans] == false) {
        cout << ans << endl;
        break;
      }
      ans++;
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

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

//??¨??????????????????????????£??????
#define MAX 7369899

int main() {

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

    vector<bool> p(MAX, false);
    int j = m;
    int ans;
    while (n > 0) {
      if (p[j] == false) {
        ans = j;
        for (int k = j; k < MAX; k += j) {
          p[k] = true;
        }
        n--;
      }
      j++;
    }

    while (1) {
      if (p[ans] == false) {
        cout << ans << endl;
        break;
      }
      ans++;
    }
  }

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

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) REP(i, 0, n)
#define REP(i, s, e) for (int i = (s); i < (int)(e); i++)
#define pb push_back
#define all(r) (r).begin(), (r).end()
#define rall(r) (r).rbegin(), (r).rend()
#define fi first
#define se second

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

const int INF = 1e9;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main() {
  int n, m;
  while (scanf("%d %d", &m, &n) != EOF) {
    if (n == 0 && m == 0)
      break;
    const int Max = 7368791 + 10;
    // set<int> st;
    // REP(i, m , Max) st.insert(i);
    // rep(i, n) {
    // 	int t = *st.begin();
    // 	for(int j = t; j < Max; j += t) {
    // 		if(st.count(j)) st.erase(j);
    // 	}
    // }
    // cout << *st.begin() << endl;
    vi v(Max, 0);
    int cnt = 0;
    REP(i, m, Max) {
      if (v[i])
        continue;
      if (cnt == n) {
        printf("%d\\n", i);
        break;
      }
      cnt++;
      for (int j = i; j < Max; j += i)
        v[j] = 1;
    }
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) REP(i, 0, n)
#define REP(i, s, e) for (int i = (s); i < (int)(e); i++)
#define pb push_back
#define all(r) (r).begin(), (r).end()
#define rall(r) (r).rbegin(), (r).rend()
#define fi first
#define se second

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

const int INF = 1e9;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main() {
  int n, m;
  while (scanf("%d %d", &m, &n) != EOF) {
    if (n == 0 && m == 0)
      break;
    const int Max = 8e6;
    // set<int> st;
    // REP(i, m , Max) st.insert(i);
    // rep(i, n) {
    // 	int t = *st.begin();
    // 	for(int j = t; j < Max; j += t) {
    // 		if(st.count(j)) st.erase(j);
    // 	}
    // }
    // cout << *st.begin() << endl;
    vi v(Max, 0);
    int cnt = 0;
    REP(i, m, Max) {
      if (v[i])
        continue;
      if (cnt == n) {
        printf("%d\\n", i);
        break;
      }
      cnt++;
      for (int j = i; j < Max; j += i)
        v[j] = 1;
    }
  }
}