#C12227. Filter and Sort Primes
Filter and Sort Primes
Filter and Sort Primes
You are given a list of integers. Your task is to filter out all of the prime numbers from the list and then sort these primes in descending order. A prime number is defined as a natural number greater than 1 that has no positive divisors other than 1 and itself.
Formally, given a list (A = [a_1, a_2, \ldots, a_n]), you need to output the list (P) such that (P = {a_i \in A | a_i \text{ is prime}}) and (P) is sorted in descending order: (P = [p_1, p_2, \ldots, p_k]) where (p_1 \ge p_2 \ge \ldots \ge p_k). If there are no primes, output an empty line.
inputFormat
The input is provided via standard input (stdin) in the following format:
The first line contains an integer (n) representing the number of elements in the list.
The second line contains (n) space-separated integers.
If (n = 0), there will be no second line.
outputFormat
Output via standard output (stdout) a single line containing the filtered prime numbers sorted in descending order, separated by a single space. If there are no prime numbers in the list, print an empty line.## sample
6
10 3 5 8 15 2
5 3 2
</p>