Created
June 25, 2016 11:53
-
-
Save odanado/4a7e7371799d3be2dc27536fab3e7ffe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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