#K44492. Filter Prime Numbers
Filter Prime Numbers
Filter Prime Numbers
Given a list of integers, your task is to filter out and return only the prime numbers. A prime number is defined as a natural number greater than 1 that has no positive divisors other than 1 and itself. The solution should read input from stdin
and output the result to stdout
.
The input starts with an integer n representing the number of elements, followed by a line of n integers separated by spaces. Your output should be a single line containing the prime numbers from the input in their original order, separated by spaces. If there are no prime numbers, output an empty line.
Recall that a number \( p \) is prime if \( p > 1 \) and for all integers \( i \) such that \( 2 \leq i \leq \sqrt{p} \), \( p \) is not divisible by \( i \).
inputFormat
The first line contains an integer n indicating the number of integers in the list. The second line contains n integers separated by spaces.
Example:
9 2 4 6 7 13 15 16 19 23
outputFormat
Output a single line containing the prime numbers from the input list in their original order, separated by spaces. If no primes are found, output an empty line.
Example:
2 7 13 19 23## sample
9
2 4 6 7 13 15 16 19 23
2 7 13 19 23
</p>