#include <iostream>
#include <math.h>
using namespace std;
const int MAXN = 1e7;
int prime[MAXN]; // Array to store prime status of numbers up to 10^7
void sieve() {
// Step 1: Assume all numbers are prime
for (int i = 0; i <= MAXN; i++) {
prime[i] = 1;
}
// Step 2: Mark 0 and 1 as non-prime
prime[0] = prime[1] = 0;
// Step 3: Sieve process
for (int i = 2; i <= sqrt(MAXN); i++) {
if (prime[i]) { // If i is still prime
for (int j = i * i; j <= MAXN; j += i) {
prime[j] = 0; // Mark multiples of i as non-prime
}
}
}
}
int main() {
sieve();
int n;
cin >> n;
// Print prime numbers up to n
for (int i = 0; i <= n; i++) {
if (prime[i]) {
cout << i << " ";
}
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8bWF0aC5oPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKY29uc3QgaW50IE1BWE4gPSAxZTc7CmludCBwcmltZVtNQVhOXTsgLy8gQXJyYXkgdG8gc3RvcmUgcHJpbWUgc3RhdHVzIG9mIG51bWJlcnMgdXAgdG8gMTBeNwoKdm9pZCBzaWV2ZSgpIHsKICAgIC8vIFN0ZXAgMTogQXNzdW1lIGFsbCBudW1iZXJzIGFyZSBwcmltZQogICAgZm9yIChpbnQgaSA9IDA7IGkgPD0gTUFYTjsgaSsrKSB7CiAgICAgICAgcHJpbWVbaV0gPSAxOwogICAgfQoKICAgIC8vIFN0ZXAgMjogTWFyayAwIGFuZCAxIGFzIG5vbi1wcmltZQogICAgcHJpbWVbMF0gPSBwcmltZVsxXSA9IDA7CgogICAgLy8gU3RlcCAzOiBTaWV2ZSBwcm9jZXNzCiAgICBmb3IgKGludCBpID0gMjsgaSA8PSBzcXJ0KE1BWE4pOyBpKyspIHsKICAgICAgICBpZiAocHJpbWVbaV0pIHsgLy8gSWYgaSBpcyBzdGlsbCBwcmltZQogICAgICAgICAgICBmb3IgKGludCBqID0gaSAqIGk7IGogPD0gTUFYTjsgaiArPSBpKSB7CiAgICAgICAgICAgICAgICBw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