#C12192. 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 the numbers that are prime and then sort these prime numbers in descending order. Finally, output the list of sorted primes followed by the sum of these prime numbers.
If no prime number exists in the input, output an empty line for the list and 0
for the sum.
Recall that a prime number is a number greater than 1 which has no positive divisors other than 1
and itself. In mathematical notation, a number \( p \) is prime if and only if \( p > 1 \) and for all integers \( d \) with \( 2 \leq d \leq \sqrt{p} \), we have \( p \mod d \neq 0 \).
inputFormat
The input is given via stdin and has the following format:
- The first line contains a single integer \( n \) representing the number of elements in the list.
- The second line contains \( n \) space-separated integers.
outputFormat
The output should be sent to stdout and consist of two lines:
- The first line contains the prime numbers (if any) sorted in descending order separated by a single space. If there are no primes, output an empty line.
- The second line contains the sum of the prime numbers.
8
12 3 17 4 2 8 5 11
17 11 5 3 2
38
</p>