Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <set>
#include <cmath>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)n; i++)
int m, n;
const int LEN = 7368791 + 10;
int buf[LEN];
void fill(int k) {
for (int i = k; i < LEN; i += k) buf[i] = 1;
}
void solve() {
memset(buf, 0, sizeof(buf));
int cnt = 0;
int ans = -1;
for (int i = m; i < LEN; i++) {
if (!buf[i]) {
// cout << "found: " << i << endl;
fill(i);
cnt++;
}
ans = i ;
if (cnt == n + 1) break;
}
// rep(i, 12) cout << i << ": " << buf[i] << endl;
cout << ans << endl;
}
int main() {
while (cin >> m >> n, m) {
solve();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment