#C12721. Prime Difference
Prime Difference
Prime Difference
You are given a list of integers and its length n. Your task is to compute the difference between the largest prime number and the smallest prime number present in the list. A prime number is defined as an integer greater than 1 that has no divisors other than 1 and itself. Formally, a number \(p\) is prime if \(p > 1\) and for any integer \(d\) such that \(2 \leq d \leq \sqrt{p}\), \(p \mod d \neq 0\).
If the list does not contain any prime numbers, output -1
. If there is exactly one prime number in the list, the difference is defined as 0
(since \(p - p = 0\)).
inputFormat
The input is given from standard input (stdin) with the following format:
- The first line contains an integer
n
indicating the number of elements in the list. - If
n > 0
, the second line containsn
space-separated integers representing the elements of the list.
If n
equals 0, there will be no second line.
outputFormat
Print a single integer to standard output (stdout): the difference between the largest and smallest prime numbers in the list. If there are no primes, output -1
. If there is exactly one prime number, output 0
.
7
10 15 3 7 2 8 5
5