Closest Prime Numbers in Range
Given two positive integers left and right, find two integers num1 and num2 such that:
left <= num1 < num2 <= right.- Both
num1andnum2are prime numbers. num2 - num1is the minimum amongst all other pairs satisfying the above conditions.
Return the positive integer array ans = [num1, num2]. If there are multiple pairs satisfying these conditions, return the one with the smallest num1 value. If no such numbers exist, return [-1, -1].
Example 1
Input
left = 10, right = 19Output
[11,13]The prime numbers between 10 and 19 are 11, 13, 17, and 19; the closest gap is 2, achieved by [11, 13] and [17, 19], so [11, 13] is returned because 11 is smaller.
Example 2
Input
left = 4, right = 6Output
[-1,-1]There exists only one prime number in the given range, so the conditions cannot be satisfied.
Constraints
- 1 <= left <= right <= 10^6