Tap here to switch tabs
Problem
Submissions

Problem: Closest Prime Numbers in Range

med
30 min
Try to solve the Closest Prime Numbers in Range problem.

Statement

Given two positive integers left and right, find two prime numbers num1 and num2 such that:

  • left ≤num1<num2≤\leq num1 < num2 \leq right

  • Both num1 and num2 are prime numbers

  • The difference num2−num1num2 - num1 is the minimum possible among all valid pairs

Return the array [num1,num2][num1, num2]. If there are multiple pairs that achieve the same minimum difference, return the pair with the smallest num1. If fewer than 22 prime numbers exist in the inclusive range [[left, right]], return [−1,−1][-1, -1].

Constraints:

  • 1≤1 \leq left ≤\leq right ≤106\leq 10^6

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Closest Prime Numbers in Range

med
30 min
Try to solve the Closest Prime Numbers in Range problem.

Statement

Given two positive integers left and right, find two prime numbers num1 and num2 such that:

  • left ≤num1<num2≤\leq num1 < num2 \leq right

  • Both num1 and num2 are prime numbers

  • The difference num2−num1num2 - num1 is the minimum possible among all valid pairs

Return the array [num1,num2][num1, num2]. If there are multiple pairs that achieve the same minimum difference, return the pair with the smallest num1. If fewer than 22 prime numbers exist in the inclusive range [[left, right]], return [−1,−1][-1, -1].

Constraints:

  • 1≤1 \leq left ≤\leq right ≤106\leq 10^6