Problem p01095 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define rep(i, a, n) for (int(i) = (a); (i) < (n); (i)++)
#define repq(i, a, n) for (int(i) = (a); (i) <= (n); (i)++)
#define repr(i, a, n) for (int(i) = (a); (i) >= (n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a, b) (abs((a) - (b)) < EPS)
#define EQV(a, b) (EQ((a).X, (b).X) && EQ((a).Y, (b).Y))
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};
int const MOD = 1000000007;

namespace std {
bool operator<(const P &a, const P &b) {
  return a.X != b.X ? a.X < b.X : a.Y < b.Y;
}
} // namespace std

#define SIZE 8000000
int make(int m, int n) {
  int cnt = 0;
  bool primes[SIZE + 10] = {};
  for (int i = m; i <= SIZE; i++) {
    if (!primes[i]) {
      cnt++;
      if (cnt == n + 1)
        return i;
      for (int j = i + i; j <= SIZE; j += i) {
        primes[j] = true;
      }
    }
  }
  return 0;
}

signed main() {
  int m, n;
  while (cin >> m >> n, m || n) {
    if (m > n)
      cout << m + n << endl;
    else {
      cout << make(m, n) << endl;
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define rep(i, a, n) for (int(i) = (a); (i) < (n); (i)++)
#define repq(i, a, n) for (int(i) = (a); (i) <= (n); (i)++)
#define repr(i, a, n) for (int(i) = (a); (i) >= (n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a, b) (abs((a) - (b)) < EPS)
#define EQV(a, b) (EQ((a).X, (b).X) && EQ((a).Y, (b).Y))
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};
int const MOD = 1000000007;

namespace std {
bool operator<(const P &a, const P &b) {
  return a.X != b.X ? a.X < b.X : a.Y < b.Y;
}
} // namespace std

#define SIZE 8000000
vector<int> make(int m) {
  vector<int> primes(SIZE + 10);
  rep(i, m, SIZE) primes[i] = i;
  for (int i = m; i * i <= SIZE; i++) {
    if (primes[i]) {
      for (int j = i + i; j <= SIZE; j += i) {
        primes[j] = 0;
      }
    }
  }
  primes.erase(remove(primes.begin(), primes.end(), 0), primes.end());
  return primes;
}

signed main() {
  int m, n;
  while (cin >> m >> n, m || n) {
    if (m > n)
      cout << m + n << endl;
    else {
      vector<int> v = make(m);
      // printf("size: %d\\n", v.size());
      cout << v[n] << endl;
    }
  }
  return 0;
}