Given two positive integers left and right, find two primes num1 and num2 with left <= num1 < num2 <= right such that num2 - num1 is as small as possible. Return [num1, num2]. If several pairs share the smallest gap, return the one with the smallest num1. If no such pair exists, return [-1, -1].
Given two positive integers left and right, find two primes num1 and num2 with left <= num1 < num2 <= right such that num2 - num1 is as small as possible. Return [num1, num2]. If several pairs share the smallest gap, return the one with the smallest num1. If no such pair exists, return [-1, -1].
Example 1:
Input: {"left":10,"right":19}
Output: [11,13]
Constraints:
1≤left≤right≤106
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"left":10,"right":19}
Build a sieve up to 19: every number starts unmarked, and each prime up to sqrt(19) = 4 will cross out its multiples.