Skip to content

Instantly share code, notes, and snippets.

@odanado
Created June 25, 2016 11:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save odanado/4a7e7371799d3be2dc27536fab3e7ffe to your computer and use it in GitHub Desktop.
Save odanado/4a7e7371799d3be2dc27536fab3e7ffe to your computer and use it in GitHub Desktop.
#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