Skip to content

Instantly share code, notes, and snippets.

@yeopgi
Created August 28, 2021 05:22
Show Gist options
  • Select an option

  • Save yeopgi/cf7f83ea132a254b88dd9e1d95b1a856 to your computer and use it in GitHub Desktop.

Select an option

Save yeopgi/cf7f83ea132a254b88dd9e1d95b1a856 to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
const int MAX = 1000000;
bool check[MAX+1];
int main() {
check[0] = check[1] = true;
for (int i=2; i*i<=MAX; i++) {
if (check[i] == false) {
for (int j=i+i; j<=MAX; j+=i) {
check[j] = true;
}
}
}
int m, n;
cin >> m >> n;
for (int i=m; i<=n; i++) {
if (check[i] == false) {
cout << i << '\n';
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment