#K69612. Sieve of Eratosthenes

    ID: 33126 Type: Default 1000ms 256MiB

Sieve of Eratosthenes

Sieve of Eratosthenes

Given an integer \(n\), your task is to output all prime numbers up to \(n\) (inclusive) using the Sieve of Eratosthenes algorithm. The algorithm works by iteratively marking the multiples of each prime number starting from \(2\). After marking, the numbers that remain unmarked are the prime numbers. The input is provided through standard input, and the result should be printed to standard output.

inputFormat

The input consists of a single line containing an integer \(n\). Note that \(n\) can be less than 2. In such cases, the output should be an empty line.

outputFormat

Print the prime numbers up to \(n\) in one line separated by a single space. If there are no prime numbers, output an empty line.

## sample
10
2 3 5 7