The First Meeting
Practice
3.3 (26 votes)
Easy
Math
Primality test
Problem
94% Success 9619 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code
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, \(A_i\), 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:
\(1 \le N \le 10^6\)
\(1 \le A_i \le 10^6\)
Sample Input
5 1 2 3 4 5
Sample Output
3
Explanation
\(A = \{1, 2, 3, 4, 5\}\).
Largest prime is 5 and smallest prime is 2. So the answer will be \(5 - 2 = 3\).
Code Editor
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor
Submissions
Please login to view your submissions
Similar Problems
Points:20
17 votes
Tags:
Ad-HocApprovedBasic ProgrammingEasyImplementationOpen
Points:20
114 votes
Tags:
EasyMathNumber TheoryPrimality test
Points:20
17 votes
Tags:
EasyGrammar-VerifiedMathNumber TheoryPrimality testPrime number
Editorial
Login to unlock the editorial
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor