Class Solution
java.lang.Object
g2501_2600.s2523_closest_prime_numbers_in_range.Solution
2523 - Closest Prime Numbers in Range.<p>Medium</p>
<p>Given two positive integers <code>left</code> and <code>right</code>, find the two integers <code>num1</code> and <code>num2</code> such that:</p>
<ul>
<li><code>left <= nums1 < nums2 <= right</code> .</li>
<li><code>nums1</code> and <code>nums2</code> are both <strong>prime</strong> numbers.</li>
<li><code>nums2 - nums1</code> is the <strong>minimum</strong> amongst all other pairs satisfying the above conditions.</li>
</ul>
<p>Return <em>the positive integer array</em> <code>ans = [nums1, nums2]</code>. <em>If there are multiple pairs satisfying these conditions, return the one with the minimum</em> <code>nums1</code> <em>value or</em> <code>[-1, -1]</code> <em>if such numbers do not exist.</em></p>
<p>A number greater than <code>1</code> is called <strong>prime</strong> if it is only divisible by <code>1</code> and itself.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> left = 10, right = 19</p>
<p><strong>Output:</strong> [11,13]</p>
<p><strong>Explanation:</strong> The prime numbers between 10 and 19 are 11, 13, 17, and 19.</p>
<p>The closest gap between any pair is 2, which can be achieved by [11,13] or [17,19].</p>
<p>Since 11 is smaller than 17, we return the first pair.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> left = 4, right = 6</p>
<p><strong>Output:</strong> [-1,-1]</p>
<p><strong>Explanation:</strong> There exists only one prime number in the given range, so the conditions cannot be satisfied.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= left <= right <= 10<sup>6</sup></code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
closestPrimes
public int[] closestPrimes(int left, int right)
-