|
| 1 | +<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> |
| 2 | + |
| 3 | +<ul> |
| 4 | + <li><code>left <= num1 < num2 <= right </code>.</li> |
| 5 | + <li>Both <code>num1</code> and <code>num2</code> are <span data-keyword="prime-number">prime numbers</span>.</li> |
| 6 | + <li><code>num2 - num1</code> is the <strong>minimum</strong> amongst all other pairs satisfying the above conditions.</li> |
| 7 | +</ul> |
| 8 | + |
| 9 | +<p>Return the positive integer array <code>ans = [num1, num2]</code>. If there are multiple pairs satisfying these conditions, return the one with the <strong>smallest</strong> <code>num1</code> value. If no such numbers exist, return <code>[-1, -1]</code><em>.</em></p> |
| 10 | + |
| 11 | +<p> </p> |
| 12 | +<p><strong class="example">Example 1:</strong></p> |
| 13 | + |
| 14 | +<pre> |
| 15 | +<strong>Input:</strong> left = 10, right = 19 |
| 16 | +<strong>Output:</strong> [11,13] |
| 17 | +<strong>Explanation:</strong> The prime numbers between 10 and 19 are 11, 13, 17, and 19. |
| 18 | +The closest gap between any pair is 2, which can be achieved by [11,13] or [17,19]. |
| 19 | +Since 11 is smaller than 17, we return the first pair. |
| 20 | +</pre> |
| 21 | + |
| 22 | +<p><strong class="example">Example 2:</strong></p> |
| 23 | + |
| 24 | +<pre> |
| 25 | +<strong>Input:</strong> left = 4, right = 6 |
| 26 | +<strong>Output:</strong> [-1,-1] |
| 27 | +<strong>Explanation:</strong> There exists only one prime number in the given range, so the conditions cannot be satisfied. |
| 28 | +</pre> |
| 29 | + |
| 30 | +<p> </p> |
| 31 | +<p><strong>Constraints:</strong></p> |
| 32 | + |
| 33 | +<ul> |
| 34 | + <li><code>1 <= left <= right <= 10<sup>6</sup></code></li> |
| 35 | +</ul> |
| 36 | + |
| 37 | +<p> </p> |
| 38 | +<style type="text/css">.spoilerbutton {display:block; border:dashed; padding: 0px 0px; margin:10px 0px; font-size:150%; font-weight: bold; color:#000000; background-color:cyan; outline:0; |
| 39 | +} |
| 40 | +.spoiler {overflow:hidden;} |
| 41 | +.spoiler > div {-webkit-transition: all 0s ease;-moz-transition: margin 0s ease;-o-transition: all 0s ease;transition: margin 0s ease;} |
| 42 | +.spoilerbutton[value="Show Message"] + .spoiler > div {margin-top:-500%;} |
| 43 | +.spoilerbutton[value="Hide Message"] + .spoiler {padding:5px;} |
| 44 | +</style> |
0 commit comments