#C10258. Extract Prime Numbers from Array

    ID: 39443 Type: Default 1000ms 256MiB

Extract Prime Numbers from Array

Extract Prime Numbers from Array

You are given an array of integers. Your task is to extract all the prime numbers from the array and print them in ascending order. A number \( p \) is prime if it is greater than 1 and has no divisors other than 1 and itself. Formally, for \( p > 1 \), it is prime if and only if:

\( \forall d \in \mathbb{Z},\ 1 < d < p \Rightarrow d \nmid p \)

If there are no prime numbers in the array, print an empty line.

inputFormat

Input is read from standard input (stdin). The first line contains an integer ( n ) denoting the number of elements in the array. The second line contains ( n ) space-separated integers.

outputFormat

Output the prime numbers from the array in ascending order, separated by a space. If no prime numbers exist, output an empty line.## sample

6
3 12 5 16 7 11
3 5 7 11