Closest Prime Numbers in Range

Given two integers left and right, find the pair of primes in the range [left, right] with the smallest difference. If there is no such pair, return [-1, -1].

Input Format

left and right = interval boundaries

Output Format

pair of closest primes in the range or [-1, -1]

Constraints

  • 1 <= left <= right <= 10^6

Examples

Example 1:

Input:

left = 10
right = 19

Output:

[11,13]

Explanation:

11 and 13 are the closest primes in the range.

Example 2:

Input:

left = 4
right = 6

Output:

[-1,-1]

Explanation:

Only one prime (5) exists in the interval.

Loading...
Closest Prime Numbers in Range - Math