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

#include <algorithm>
#include <iostream>

#define MAX (7368791 + 1)

using namespace std;

bool a[MAX];

int main(void) {
  int m, n;
  while (cin >> m >> n, m || n) {
    fill(a, a + MAX, true);
    int count = 0;
    for (int i = m; i < MAX; i++) {
      if (a[i] == true) {
        if (count == n) {
          cout << i << endl;
          break;
        }
        count++;
        for (int j = i + i; j < MAX; j += i) {
          a[j] = false;
        }
      }
    }
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>

#define MAX (7368791 + 1)

using namespace std;

bool a[MAX];

int main(void) {
  int m, n;
  while (cin >> m >> n, m || n) {
    fill(a, a + MAX, true);
    int count = 0;
    for (int i = m; i < MAX; i++) {
      if (a[i] == true) {
        if (count == n) {
          cout << i << endl;
          break;
        }
        count++;
        for (int j = i + i; j < MAX; j += i) {
          a[j] = false;
        }
      }
    }
  }
  while (1)
    ;
  return 0;
}
Problem p01095 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>

using namespace std;
bool p[10010010];

int main() {

  while (1) {
    int m, n;
    cin >> m >> n;
    if (!(m || n))
      break;

    for (int i = 0; i < 10010010; i++)
      p[i] = true;
    int c = 0;
    for (int i = m; i < 10010010; i++) {
      if (p[i]) {
        c++;
        if (c == n + 1) {
          cout << i << endl;
          break;
        }
        for (int j = 2; i * j < 10010010; j++) {
          p[i * j] = false;
        }
      }
    }
  }
  return 0;
}

Error: -11

Fixed submission:

#include <iostream>

using namespace std;

int main() {

  while (1) {
    int m, n;
    cin >> m >> n;
    if (!(m || n))
      break;

    if (m > n) {
      cout << m + n << endl;
      return 0;
    }
    bool p[100100100];
    for (int i = 0; i < 100100100; i++)
      p[i] = true;
    int c = 0;
    for (int i = m; i * i <= 100100100; i++) {
      if (p[i]) {
        c++;
        if (c == n + 1) {
          cout << i << endl;
          break;
        }
        for (int j = 2; i * j < 100100100; j++) {
          p[i * j] = false;
        }
      }
    }
  }
  return 0;
}
Problem p01095 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <vector>

using namespace std;

#define ma 7368792

bool era[ma];

int main() {
  int n, m;
  while (cin >> m >> n && m != 0) {
    for (int i = 0; i < ma; i++) {
      era[i] = 0;
    }
    int count = 0;
    int x = m;
    bool flag = 0;
    while (1) {
      if (era[x] == 0) {
        count += 1;
        for (int i = x; i < ma; i += x) {
          era[i] = 1;
        }
      }
      if (count > n)
        break;
      x += 1;
    }
    cout << x << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <vector>

using namespace std;

int main() {
  int n, m;
  while (cin >> m >> n && m != 0) {
    int count = 1;
    vector<int> v;
    set<int> s;
    v.push_back(m);
    s.insert(m);
    int x = m + 1;
    bool flag = 0;
    while (1) {
      flag = 1;
      for (int i = 2; i < v[0]; i++) {
        if (x % i == 0) {
          if (s.count(x / i) == 1) {
            flag = 0;
          }
        }
      }
      if (flag == 1) {
        for (int i = 0; i < v.size(); i++) {
          if (v[i] > (int)sqrt((double)x) + 1)
            break;
          if (x % v[i] == 0) {
            flag = 0;
          }
        }
      }
      if (flag) {
        count += 1;
        v.push_back(x);
        s.insert(x);
      }
      if (count > n)
        break;
      x += 1;
    }
    cout << x << endl;
  }
  return 0;
}
Problem p01095 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <set>
#include <string>
using namespace std;
bool a[7368800];
int main() {
  int m = 3, n = 1;
  while (cin >> m >> n && n != 0 && m != 0) {
    int sum = m, n2 = n;
    fill(a, a + 7368800, false);
    while (n2 != 0 || a[sum]) {
      if (!a[sum]) {
        a[sum] = true;
        int j = 2;
        while (sum * j < 7368800) {
          a[sum * j] = true;
          j++;
        }
        n2--;
      }
      sum++;
    }
    cout << sum << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <set>
#include <string>
using namespace std;
bool a[7368800];
int main() {
  int m = 3, n = 1;
  while (/*cin >>m>> n&&*/ n != 0 && m != 0) {
    int sum = m, n2 = n;
    fill(a, a + 7368800, false);
    while (n2 != 0 || a[sum]) {
      if (!a[sum]) {
        a[sum] = true;
        int j = 2;
        while (sum * j < 7368800) {
          a[sum * j] = true;
          j++;
        }
        n2--;
      }
      sum++;
    }
    cout << sum << endl;
  }
}
Problem p01095 (C++) — buggy submission, verdict: Runtime Error

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

#define MAX 7368791

int main(void) {
  int m, n;
  bool year[MAX];

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

    for (int i = 0; i < MAX; i++)
      year[i] = false;

    int seed = 0;
    for (int i = m; i <= MAX; i++) {
      if (!year[i - 1]) {
        if (seed < n) {
          for (int j = i; j <= MAX; j += i)
            year[j - 1] = true;
          seed++;
        } else {
          seed = i;
          break;
        }
      }
    }

    printf("%d\\n", seed);
  }

  return 0;
}


Error: -11

Fixed submission:

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

#define MAX 7368791

int main(void) {
  int m, n;
  int year[MAX];

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

    for (int i = 0; i < MAX; i++)
      year[i] = false;

    int seed = 0;
    for (int i = m; i <= MAX; i++) {
      if (!year[i - 1]) {
        if (seed < n) {
          for (int j = i; j <= MAX; j += i)
            year[j - 1] = true;
          seed++;
        } else {
          seed = i;
          break;
        }
      }
    }

    printf("%d\\n", seed);
  }

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

#include <algorithm>
#include <cmath>
#include <float.h>
#include <functional>
#include <iostream>
#include <map>
#include <sstream>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;

void A();
void B();
#define INT_MAX 7368793
bool f[INT_MAX];

void del_flag(int m) {
  int tmp = m;
  while (tmp < INT_MAX) {
    f[tmp] = false;
    tmp += m;
  }
}

int main() {
  int m, n;
  while (cin >> m >> n, n) {
    for (int i = 0; i < INT_MAX; ++i) {
      f[i] = true;
    }
    int tmp = m;
    for (int i = 0; i < n; ++i) {
      while (!f[tmp])
        ++tmp;
      del_flag(tmp);
    }
    while (!f[tmp])
      ++tmp;
    cout << tmp << endl;
  }
  return 0;
}


Error: MLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <float.h>
#include <functional>
#include <iostream>
#include <map>
#include <sstream>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;

#define INT_MAX 2147483647
bool f[INT_MAX];

void del_flag(int m) {
  int tmp = m;
  while (tmp < INT_MAX) {
    f[tmp] = false;
    tmp += m;
  }
}

int main() {
  int m, n;
  while (cin >> m >> n, n) {
    for (int i = 0; i < INT_MAX; ++i) {
      f[i] = true;
    }
    int tmp = m;
    for (int i = 0; i < n; ++i) {
      while (!f[tmp])
        ++tmp;
      del_flag(tmp);
    }
    while (!f[tmp])
      ++tmp;
    cout << tmp << endl;
  }
  return 0;
}
Problem p01095 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e7 + 1;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i, r, n) for (ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i, r, n) for (ll i = (ll)(n - 1); i >= r; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define RALL(x) x.rbegin(), x.rend()
#define ll long long int
typedef vector<ll> vi;
typedef vector<pair<int, int>> vp;
typedef vector<string> vs;
typedef vector<char> vc;
ll n, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

/*--------------------template--------------------*/

#define max 7368792

int main() {
  while (true) {
    int m, n;
    cin >> m >> n;
    if (m == 0 && n == 0)
      break;
    vector<bool> used(max);
    int j = m;
    REP(i, n) {
      while (used[j])
        ++j;
      for (int k = j; k < used.size(); k += j) {
        used[k] = true;
      }
    }
    while (used[j])
      ++j;
    cout << j << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e7 + 1;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i, r, n) for (ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i, r, n) for (ll i = (ll)(n - 1); i >= r; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define RALL(x) x.rbegin(), x.rend()
#define ll long long int
typedef vector<ll> vi;
typedef vector<pair<int, int>> vp;
typedef vector<string> vs;
typedef vector<char> vc;
ll n, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

/*--------------------template--------------------*/

#define max 7368792

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

    if (m == 0 && n == 0) {
      return 0;
    } else {
      if (m >= n) {
        cout << m + n << endl;
      } else {
        vi v;

        REP(i, m) {
          int a = m + i;
          v.push_back(a);
        }

        cnt = n - m + 1;
        int i = v[v.size() - 1];
        while (cnt > 0) {
          REP(j, v.size()) {
            if (i % v[j] == 0) {
              break;
            }
            if (j == v.size() - 1) {
              v.push_back(i);
              cnt--;
            }
          }
          i++;
        }
        cout << v[v.size() - 1] << endl;
      }
    }
  }
}
Problem p01095 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define dump(x) cout << (x) << '\\n';
typedef int64_t Int;
Int mod = 1e9 + 7;
Int INF = 1e9 + 7;

bool v[8000000];

int main() {
  while (true) {
    int m, n;
    cin >> m >> n;
    if (m == 0)
      break;
    memset(v, 0, sizeof(v));
    int i = m;
    while (n >= 0) {
      if (v[i]) {
        i++;
        continue;
      }
      for (int j = 1; j * i <= 7400000; j++)
        v[i * j] = true;
      i++;
      n--;
    }
    dump(i - 1);
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define dump(x) cout << (x) << '\\n';
typedef int64_t Int;
Int mod = 1e9 + 7;
Int INF = 1e9 + 7;

// vector<pair<int, int>> v[19803];
int v[500001];

int main() {
  // vector<pair<int, int>> v
  while (true) {
    int m, n;
    cin >> m >> n;
    if (m == 0)
      break;
    set<int> st;
    for (int i = m; i <= 7368791; i++) {
      bool p = true;
      for (int j = 2; j * j <= i; j++) {
        if (i % j == 0 && (st.count(j) > 0 || st.count(i / j) > 0)) {
          p = false;
          break;
        }
      }
      if (p) {
        if (n == 0) {
          dump(i);
          break;
        }
        st.insert(i);
        n--;
      }
    }
  }
  // cout << endl;
  // for (auto x : v) cout << x.first << " " << x.second << endl;
  return 0;
}
Problem p01095 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n, m, i, j, k, f; // sosu[SIZE] = {};

  while (1) {
    int count = 0, a[SIZE] = {}, temp = 0;
    cin >> m >> n;

    if (m == 0 && n == 0)
      break;

    for (i = m; count <= n; i++) {
      if (a[i] == 0) {
        count++;
        for (j = i; j < SIZE; j += i) {
          a[j] = 1;
        }
      }
    }

    cout << i - 1 << endl;
  }

  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  int n, m, i, j, k, sosu[SIZE] = {}, f;

  sosu[0] = 2;
  for (i = 3; k < SIZE; i++) {
    f = 0;
    for (j = 3; j * j <= i; j += 2) {
      if (i % j == 0) {
        f = 1;
        break;
      }
    }
    if (f == 0)
      sosu[k++] = i;
  }

  while (1) {
    int count = 0, a[1] = {}, temp = 0;
    cin >> m >> n;

    if (m == 0 && n == 0)
      break;

    for (i = 0; sosu[i] < m; i++)
      ;
    k = i;

    for (i = m; count <= n; i++) {
      if (sosu[k] == i && k < SIZE) {
        count++;
        continue;
      }
      f = 0;
      for (j = 2; j * j <= i; j++) { // cout<<i<<" a "<<j<<endl;
        if (i % j == 0) {            // cout<<i<<" "<<j<<endl;
          if (m <= j && j < i) {
            f = 1;
            break;
          } else if (m <= i / j && i / j < i) {
            f = 1;
            break;
          }
        }
      }
      if (f == 0)
        count++;
    }

    cout << i - 1 << endl;
  }

  return 0;
}
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 = 7400000;
    vector<bool> prime(tmp, false);
    int t = 0;
    for (i = n; i < tmp; i++)
      if (prime[i] == false) {
        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 = 7400000;
    vi prime(tmp, 0);
    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 <bits/stdc++.h>
using namespace std;
#define MAX 7777777
int main() {
  int n, m, t = 0;
  bool a[MAX];
  while (cin >> n >> m, n) {
    t = 0;
    memset(a, false, sizeof(a));
    for (int j = n; j < MAX; j++) {
      if (!a[j]) {
        for (int k = j; k < MAX; k += j) {
          a[k] = true;
        }
        t++;
      }
      if (m == 1)
        break;
      if (m != 1 && t == m)
        break;
    }
    for (int i = n; i < MAX; i++) {
      if (!a[i]) {
        cout << i << endl;
        break;
      }
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define Pasharin using namespace std
#define REP(i, a, b) for (int i = a; i < b; ++i)

int p(int x) {
  if (x % 2 == 0)
    return 0;
  for (int i = 3; i * i <= x; i += 2) {
    if (x % i == 0)
      return 0;
  }
  return 1;
}

Pasharin;
int main() {
  while (1) {
    int n, m, a[500001], cnt = 1;
    cin >> n >> m;
    if (n + m == 0)
      break;
    a[0] = n;
    for (int i = n + 1; 1; i++) {
      int b = 0;
      if (!(i > n * n)) {
        for (int j = 0; j < cnt; j++) {
          if (i % a[j] == 0) {
            b++;
            break;
          }
          if (a[j] * a[j] > i * n || a[j] * 2 > i)
            break;
        }
      } else {
        if (!p(i))
          b++;
      }
      if (b == 0) {
        cnt++;
        a[cnt - 1] = i;
        if (cnt > m) {
          cout << i << endl;
          break;
        }
      }
    }
  }
  return 0;
}
Problem p01095 (C++) — buggy submission, verdict: Time Limit Exceeded

#include "algorithm"
#include "bitset"
#include "climits"
#include "cmath"
#include "cstdio"
#include "functional"
#include "iomanip"
#include "iostream"
#include "list"
#include "map"
#include "queue"
#include "random"
#include "set"
#include "stack"
#include "string"
#include "unordered_map"
#include "unordered_set"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;

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

  cin >> N >> M;
  while (N) {
    bitset<8000000> b(false);
    int index = N;
    int cnt = 0;
    while (cnt <= M) {
      if (b[index]) {
        index++;
        continue;
      }
      cnt++;
      for (int i = index; i < 8000000; i += index) {
        b[i] = true;
      }
      index++;
    }
    cout << index - 1 << endl;
    cin >> N >> M;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include "algorithm"
#include "bitset"
#include "climits"
#include "cmath"
#include "cstdio"
#include "functional"
#include "iomanip"
#include "iostream"
#include "list"
#include "map"
#include "queue"
#include "random"
#include "set"
#include "stack"
#include "string"
#include "unordered_map"
#include "unordered_set"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;

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

  cin >> N >> M;
  while (N) {
    bitset<8000000> b;
    int index = N;
    int cnt = 0;
    while (cnt < M) {
      if (b[N]) {
        index++;
        continue;
      }
      cnt++;
      for (int i = index; i < 8000000; i += index) {
        b[i] = true;
      }
      index++;
    }
    cout << index << endl;
    cin >> N >> M;
  }
  return 0;
}
Problem p01095 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<pint> vpint;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, n) for (int i = n - 1; i >= (0); i--)
#define reps(i, f, n) for (int i = (f); i < (n); i++)
#define each(it, v)                                                            \\
  for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)
#define all(v) (v).begin(), (v).end()
#define eall(v) unique(all(v), v.end())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a) < (b)) ? (b) : (a))
#define chmin(a, b) a = (((a) > (b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;

int m, n;
int dat[7400000];

int main(void) {
  while (1) {
    scanf("%d %d", &m, &n);
    if (m == 0 && n == 0)
      return 0;
    rep(i, 7400000) dat[i] = 0;

    int cnt = 0;
    int d = m;
    while (cnt < n) {
      if (dat[d] != 0) {
        d++;
        continue;
      }
      for (int j = d; j <= 7400000; j += d) {
        dat[j] = 1;
      }
      cnt++;
      d++;
    }

    reps(i, m, 7400000) {
      if (dat[i] == 0) {
        printf("%d\\n", i);
        break;
      }
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<pint> vpint;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, n) for (int i = n - 1; i >= (0); i--)
#define reps(i, f, n) for (int i = (f); i < (n); i++)
#define each(it, v)                                                            \\
  for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)
#define all(v) (v).begin(), (v).end()
#define eall(v) unique(all(v), v.end())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a) < (b)) ? (b) : (a))
#define chmin(a, b) a = (((a) > (b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;

int m, n;
int dat[8000100];

int main(void) {
  while (1) {
    cin >> m >> n;
    if (m == 0 && n == 0)
      return 0;
    rep(i, 8000100) dat[i] = 0;

    int cnt = 0;
    int d = m;
    while (cnt < n) {
      if (dat[d] != 0) {
        d++;
        continue;
      }
      for (int j = d; j <= 8000000; j += d) {
        dat[j] = 1;
      }
      cnt++;
      d++;
    }

    reps(i, m, 80000001) {
      if (dat[i] == 0) {
        printf("%d\\n", i);
        break;
      }
    }
  }
  return 0;
}