#C6317. Prime Numbers Generator
Prime Numbers Generator
Prime Numbers Generator
Given a positive integer \(n\), your task is to generate all prime numbers less than or equal to \(n\). A prime number is an integer greater than 1 that has no positive divisors other than 1 and itself.
This problem can be solved efficiently using the Sieve of Eratosthenes. The idea is to create a boolean array \(sieve[0 \ldots n]\) initialized to true
(except for index 0 and 1 which are not prime), and then mark the multiples of each prime number starting from 2.
For example, if \(n = 10\), the prime numbers are: 2, 3, 5, and 7.
inputFormat
The input consists of a single integer \(n\) read from stdin.
Constraints: \(1 \le n \le 10^6\).
outputFormat
Output all prime numbers less than or equal to \(n\) in increasing order, separated by a single space. The output should be written to stdout. If there are no prime numbers, output an empty line.
## sample10
2 3 5 7