#C4927. Sieve of Eratosthenes

    ID: 48519 Type: Default 1000ms 256MiB

Sieve of Eratosthenes

Sieve of Eratosthenes

Given a positive integer \(n\), your task is to output all prime numbers less than or equal to \(n\) using the Sieve of Eratosthenes algorithm. A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself.

The Sieve of Eratosthenes is an efficient algorithm to find all primes up to a given limit \(n\). The idea is to iteratively mark the multiples of each prime number starting from 2.

inputFormat

The input consists of a single integer (n) ((0 \le n \le 10^6)). It is provided via standard input.

outputFormat

Output, on a single line, all prime numbers less than or equal to (n) separated by a single space. If there are no primes, print nothing. The output is to standard output.## sample

10
2 3 5 7