#C3682. Median Prime Finder
Median Prime Finder
Median Prime Finder
Given a sequence of n integers, your task is to find the median of all the prime numbers contained in the sequence. A prime number is defined as a natural number greater than 1 that has no positive divisors other than 1 and itself.
If there are no prime numbers in the sequence, output -1
.
If the number of prime numbers is odd, the median is the middle element after sorting them in non-decreasing order. If the number of prime numbers is even, then the median is defined as:
[ \text{median} = \text{round}\left(\frac{p_{\frac{m}{2}-1} + p_{\frac{m}{2}}}{2}\right) ]
where \(m\) is the total count of prime numbers, \(p_i\) represents the i-th smallest prime in the sorted order, and \(\text{round}(\cdot)\) rounds its argument to the nearest integer.
Input Format: The first line contains one integer n indicating the number of integers in the sequence. The second line contains n space-separated integers.
Output Format: Print a single integer representing the median of the prime numbers found or -1
if there are no prime numbers.
inputFormat
The input is read from standard input (stdin) and consists of two lines. The first line contains an integer n (the number of elements). The second line contains n space-separated integers.
outputFormat
Output a single integer on standard output (stdout) which is the median of the prime numbers found. If none are found, output -1.## sample
4
4 6 8 10
-1