#K56767. Filter Prime Numbers
Filter Prime Numbers
Filter Prime Numbers
You are given a list of integers. Your task is to filter out all the prime numbers from the list and output them in the same order they appear. A number n is considered prime if and only if it is greater than 1 and has no divisors other than 1 and itself. In mathematical terms, a number n is prime if:
\( n > 1 \) and for all integers \( i \) where \( 2 \le i \le \sqrt{n} \), \( i \) does not divide \( n \).
This problem tests your ability to implement a basic primality test and to filter a list based on a condition.
inputFormat
The input is given via stdin and consists of two lines:
- The first line contains a single integer N representing the number of elements in the list.
- The second line contains N space-separated integers.
If there are no prime numbers in the list, output an empty line.
outputFormat
The output should be written to stdout. Print on one line all the prime numbers from the input list, separated by a single space. If there are no prime numbers, output an empty line.
## sample5
2 3 4 5 6
2 3 5