#C2656. Extract and Sort Prime Numbers
Extract and Sort Prime Numbers
Extract and Sort Prime Numbers
You are given an unsorted array of integers. Your task is to extract all the prime numbers from the array and output them in descending order.
A prime number is defined as an integer greater than 1 which has no divisors other than 1 and itself. That is, a number \( p \) is prime if and only if \( p > 1 \) and for all integers \( d \) such that \( 2 \le d \le \sqrt{p} \), \( p \) is not divisible by \( d \).
If there are no prime numbers in the array, output an empty line.
inputFormat
The input is read from standard input (stdin) and consists of two lines:
- The first line contains a single integer \( n \) which denotes the number of elements in the array.
- The second line contains \( n \) space-separated integers.
outputFormat
Output the prime numbers found in the array in descending order in one line, separated by a single space. If no prime numbers are found, print an empty line.
## sample7
10 15 3 7 11 18 29
29 11 7 3