#C13029. Prime Number Extraction in Descending Order

    ID: 42522 Type: Default 1000ms 256MiB

Prime Number Extraction in Descending Order

Prime Number Extraction in Descending Order

Given a list of integers, your task is to extract all the prime numbers and then sort them in descending order. A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. The result should list the primes in a single line, separated by spaces.

Input Format: The first line of input contains an integer N, the number of elements in the list. The second line contains N space-separated integers.

Output Format: Print the prime numbers in descending order separated by spaces. If no prime numbers exist, output a blank line.

Note: Use \( \LaTeX \) format for any mathematical formulas. For example, a prime number \( p \) satisfies:

[ p \in \mathbb{N},\ p > 1, \text{ and } \forall d \in \mathbb{N} \ (1 < d < p \Rightarrow p \mod d \neq 0). ]

inputFormat

The input consists of two lines:

  • The first line contains an integer N (1 \(\leq N \leq 10^5\)), indicating the number of integers.
  • The second line contains N space-separated integers. Each integer fits in a 32-bit signed integer.

outputFormat

Output a single line with the prime numbers extracted from the list in descending order separated by a single space. If there are no prime numbers, output a blank line.

## sample
6
10 15 3 7 9 17
17 7 3