#C12891. Prime Numbers with Statistics

    ID: 42368 Type: Default 1000ms 256MiB

Prime Numbers with Statistics

Prime Numbers with Statistics

You are given a list of integers. Your task is to filter out the prime numbers from the list in the original order and then compute the mean and median of these prime numbers. The median should be computed after sorting the prime numbers in non-decreasing order. If the list of prime numbers is empty, output an empty list (represented by []) and print None for both the mean and the median.

In mathematical terms, let \(P = [p_1, p_2, ..., p_k]\) be the list of prime numbers extracted, where the order of appearance in the original input is preserved. The mean is defined as \(\text{mean} = \frac{1}{k}\sum_{i=1}^k p_i\). If we let \(P_s\) be the sorted version of \(P\), then the median is defined as follows:

  • If \(k\) is odd, \(\text{median} = P_s[\lfloor k/2 \rfloor]\).
  • If \(k\) is even, \(\text{median} = \frac{P_s[\frac{k}{2}-1] + P_s[\frac{k}{2}]}{2}\).

Input is read from standard input (stdin) and output should be printed to standard output (stdout). The first line of input contains an integer \(n\) that indicates the number of elements. The next line contains \(n\) space-separated integers. The output should consist of two lines. The first line prints the prime numbers in their original order separated by a space (or [] if there are none), and the second line prints the mean and median separated by a space (or None None if there are no prime numbers).

inputFormat

The input is given via standard input (stdin). The first line contains an integer (n), representing the number of elements in the list. The second line contains (n) space-separated integers representing the values in the list.

outputFormat

Print the results to standard output (stdout) in two lines. The first line should display the prime numbers (in the order they appear in the input) separated by a space. If there are no prime numbers, print []. The second line should display the mean and median (separated by a space) of the prime numbers. If no prime exists, output None None.## sample

9
4 6 7 9 11 13 15 18 19
7 11 13 19

12.5 12.0

</p>