#C14268. Sieve of Eratosthenes: Compute Prime Numbers
Sieve of Eratosthenes: Compute Prime Numbers
Sieve of Eratosthenes: Compute Prime Numbers
In this problem, you are required to compute all prime numbers up to a given integer n using the Sieve of Eratosthenes algorithm. The sieve algorithm efficiently finds all prime numbers less than or equal to n with a time complexity of $O(n \log \log n)$.
Your task is to read an integer from standard input and output all prime numbers between 2 and n (inclusive) in ascending order, separated by a single space. If there are no primes in the range (i.e. when n is less than 2), output nothing.
inputFormat
The input consists of a single integer n provided via standard input.
Example:
30
outputFormat
Output all prime numbers from 2 up to n (inclusive) in a single line, separated by a single space. If no prime numbers exist for the given input, output nothing.
Example:
2 3 5 7 11 13 17 19 23 29## sample
1