#C13286. Sieve of Eratosthenes

    ID: 42807 Type: Default 1000ms 256MiB

Sieve of Eratosthenes

Sieve of Eratosthenes

Given a positive integer n, this problem requires you to compute all prime numbers in the range [1, n] using the Sieve of Eratosthenes algorithm. The algorithm works by iteratively marking the multiples of each prime number starting from 2. The primes are then collected and printed in ascending order. If there are no prime numbers in the range, print nothing.

Note: The input will always be a valid positive integer.

The Sieve of Eratosthenes is a classical algorithm in number theory. In LaTeX, its description can be summarized as follows:

$$\text{For an integer } n, \; \{2, 3, \ldots, n\} \rightarrow \text{ filter out multiples to leave the primes.} $$

inputFormat

The input consists of a single line containing one positive integer n (1 ≤ n ≤ 10^6).

outputFormat

Print all prime numbers from 1 to n in ascending order separated by a space. If there are no primes in the range, print nothing.

## sample
10
2 3 5 7