#K80167. Prime Number Generation using Sieve of Eratosthenes

    ID: 35471 Type: Default 1000ms 256MiB

Prime Number Generation using Sieve of Eratosthenes

Prime Number Generation using Sieve of Eratosthenes

Given a non-negative integer \(n\), your task is to output all prime numbers less than or equal to \(n\) using the Sieve of Eratosthenes algorithm.

If \(n < 2\), there are no primes, and you should output nothing. The algorithm works by initially assuming that every number \(\ge 2\) is prime. Then, starting from 2, it marks multiples of each prime as non-prime.

Example: For input 10, the output should be: 2 3 5 7.

inputFormat

The input consists of a single integer \(n\) (which can be zero or negative) provided via standard input.

outputFormat

Output all prime numbers less than or equal to \(n\> in ascending order separated by a single space. If there are no prime numbers, output nothing.

## sample
10
2 3 5 7

</p>