The First Meeting

3.3

26 votes
Easy, Math, Primality test
Problem

Given an array, A, of length N. Find the absolute difference between the smallest and largest prime number in array A.

Input:
First line contains an integer, N, number of points.
Second line contains N space separated integers, Ai, denoting the elements of the array A.

Output:
Print the absolute difference between the smallest and largest prime number in array A, otherwise 1.

Constraints:
1N106
1Ai106

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

A={1,2,3,4,5}.
Largest prime is 5 and smallest prime is 2. So the answer will be 52=3.

Editor Image

?