#K35702. Generate Prime Numbers

    ID: 25590 Type: Default 1000ms 256MiB

Generate Prime Numbers

Generate Prime Numbers

Given an integer n, generate all prime numbers less than or equal to n. A prime number is defined as a number greater than 1 that has no divisors other than 1 and itself, i.e., \(p > 1\) and for any integer \(a\) such that \(1 < a < p\), \(a\) does not divide \(p\).

You are required to output the prime numbers in ascending order. An efficient way to solve this problem is to use the Sieve of Eratosthenes.

inputFormat

A single integer (n) provided via standard input (stdin).

outputFormat

Print all prime numbers less than or equal to (n) in one line, separated by a single space, via standard output (stdout). If there are no prime numbers, output an empty line.## sample

10
2 3 5 7