Skip to content

Commit 927d4c6

Browse files
Update prime_game.md
1 parent bfe172b commit 927d4c6

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

Techgig Code Gladiators 2021/open round/prime_game.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,70 @@ Rax will randomly provide you a range [ L , R ] (both inclusive) and you have to
1212
<li>There is only one distinct prime number in the given range. The maximum difference in this case would be 0.</li>
1313
<li>There are no prime numbers in the given range. The output for this case would be -1.</li>
1414
</ol>
15+
16+
To win the game, the participant should answer the prime difference correctly for the given range.
17+
18+
#### Example:
19+
20+
##### Range: [ 1, 10 ]:
21+
22+
The maximum difference between the prime numbers in the given range is 5.
23+
Difference = 7 - 2 = 5
24+
25+
##### Range: [ 5, 5 ]:
26+
27+
There is only one distinct prime number so the maximum difference would be 0.
28+
29+
##### Range: [ 8 , 10 ]:
30+
31+
There is no prime number in the given range so the output for the given range would be -1.
32+
33+
Can you win the game?
34+
35+
<b>Input Format:</b>
36+
37+
The first line of input consists of the number of test cases, T
38+
Next T lines each consists of two space-separated integers, L and R
39+
40+
<b>Constraints:</b>
41+
42+
1<= T <=10
43+
2<= L<= R<=10^6
44+
45+
<b>Output Format</b>
46+
47+
For each test case, print the maximum difference in the given range in a separate line.
48+
49+
##### Sample Test Case:
50+
51+
Input:
52+
```
53+
5
54+
5 5
55+
2 7
56+
8 10
57+
10 20
58+
4 5
59+
```
60+
Output:
61+
```
62+
0
63+
5
64+
-1
65+
8
66+
0
67+
```
68+
Explanation:
69+
```
70+
Test Case 1: [ 5 - 2 ] = 3
71+
72+
Test Case 2: [ 7 - 2 ] = 5
73+
74+
Test Case 3: No prime number in the given range. Output = -1
75+
76+
Test Case 4: [ 19 - 11 ] = 8
77+
78+
Test Case 5: The difference would be 0 since there is only one prime number in the given range.
79+
```
1580

1681

0 commit comments

Comments
 (0)