#K51257. Average of Prime Numbers
Average of Prime Numbers
Average of Prime Numbers
Given a list of n integers, compute the average of all the prime numbers present in the list. 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 list, the output should be 0.0.
You can use the following mathematical formula for the arithmetic mean of primes:
\(\text{Average} = \frac{\sum_{p \in P} p}{|P|}\), where \(P\) is the set of prime numbers.
The input is read from standard input and the output is written to standard output.
inputFormat
The first line contains an integer n
denoting the number of elements in the list. The second line contains n
space-separated integers.
For example:
8 2 3 4 5 6 7 8 9
outputFormat
Output a single floating-point number which is the average of all prime numbers in the list. If there are no prime numbers, output 0.0
.
For instance, for the sample input above, the output should be:
4.25## sample
8
2 3 4 5 6 7 8 9
4.25