# Prime Game SOLUTIONS CODECHEF SSEC0006

Page Contents

## Prime Game SOLUTION SSEC0006

Two companions who are acceptable in science and one of them provoked the other one to locate the Prime Number in a given range say ” A ” and ” B ” , here An and B are the range , however it appears simple to illuminate , so he wound the inquiry and said print Prime Number Pair whose augmentation comes in the middle of (A * B) and (A/2 * B/2).

Info:

First Line will be Range A

Second Line will be Range B

Yield:

Print the Prime Number Pair

Information Constraints:

1 ≤ Range ≤ 1000

First range must be littler than the Second range.

Model Input:

10

30

Model Output:

11,13

11,17

11,19

11,23

13,17

13,19

13,23

Clarification:

A = 10 and B = 30 (Range)

Prime Number between An and B = {11, 13, 17, 19 23, 29}

A * B = 300

A/2 * B/2 = 75

1) 11 * 13 = 143 (75 ≤ 143 ≤ 300 ) ✓

2) 11 * 17 = 187 (75 ≤ 187 ≤ 300 ) ✓

3) 11 * 19 = 209 (75 ≤ 209 ≤ 300 ) ✓

4) 11 * 23 = 253 (75 ≤ 253 ≤ 300 ) ✓

5) 13 * 17 = 221 (75 ≤ 221 ≤ 300 ) ✓

6) 13 * 19 = 247 (75 ≤ 247 ≤ 300 ) ✓

7) 13 * 23 = 299 (75 ≤ 299 ≤ 300 ) ✓

Rest of the number won’t come in the middle of the range.

Hey guys, I hope you all are doing great.

Before I start we can see in the question itself how well it’s been already explained but still if you guys have your doubts, continue with me.

Now lets try to understand what this question wants from us, If we see here A & B are the two ranges basically right.

So, what makes it so interesting there is a twist which question says Range A is now (A/2*B/2), As per our given explanation in the question. HOLD ON!!! is that right? NO! What if the Range A is (A*B)? and how we will know that what range value will come in Range A, Well I know most of you are smart and clever and already know what is the answer Really Great.

### So what will be the Range A Value?

Compare them both, but what we have to compare ?

Let’s see that,

if (A/2*B/2) is around 600 okay we are just assuming its value, and (A*B) is around 800 so which one is smaller that value will be given to Range A because it’s the starting range right and obviously it is going to be smaller then Range B. Even the constraints says that

Input Constraints:
1 ≤ Range ≤ 1000
First range must be smaller than the Second range.

So,  now we know which value will go where if it’s smaller then to Range A if its bigger then Range B.

I hope this First step is clear.

Now lets see what we have to do in the question.

I’m going to take my own prime number range, to make it more simple and clear.

Range A =5

Range B=20

Our first motive will be to get the prime numbers from 5 to 20

Prime Number from 5 to 20

“5 7 11 13 17 19” this are the prime numbers of our given range now lets TWIST THEM UP.

Now, we are going to find the values for (A*B) and (A/2*B/2)

So,

A*B= 5*20 = 100

A/2 * B/2 = 5/2 * 20/2 = 2 * 10 = 20 (Now here 5/2 will give float but we have to take integer).

So, we find our new ranges now okay. Let’s call them as

Range A = 20

Range B=100

Question is why this way why not Range A =100. Because it will start from smaller value to larger value. If you remember the CONSTRAINTS!

So, we are with our new ranges and prime value.

Now lets do the pairing of the prime numbers “5 7 11 13 17 19”

5*7 = 35

5*11 = 55

5*13 = 65

5*17 = 85

5*19 = 95

7*11 = 77

7*13 = 91

7*17 = 119

7*19 = 133

11*13 = 143

11*17 = 187

11*19 = 209

13*17 = 221

13*19 = 247

17*19  = 323

WOW! looks scary to me atleast.

So now we got our pair values lets see what will be the output of  new Range A = 20 and Range B = 100

Let’s do it now,

A=20   B=100

20<= 5*7 <= 100

20 <= 35 <= 100 { TRUE}

Now I solved it in this manner to make it clear how it’s looks like, Let’s solve it directly now.

20 <= 35 <= 100 { TRUE}

20 <= 55 <= 100 { TRUE}

20 <= 65 <= 100 { TRUE}

20 <= 77 <= 100 { TRUE}

20 <= 85 <= 100 { TRUE}

20 <= 85 <= 100 { TRUE}

20 <= 91 <= 100 { TRUE}

20 <= 95 <= 100 { TRUE}

20 <= 119 <= 100 { FALSE}

20 <= 133 <= 100 { FALSE}

20 <= 143 <= 100 { FALSE}

20 <= 187 <= 100 { FALSE}

Now if you see I stopped after few False Because our limit is “Less Than or Equal to” 100.

You might also notice that why 77 is coming before 95 but while calculating the pairs it was after 95. It’s because we have to compare from smaller to larger, it will help while printing the Output.

So, Our Input was A=5 and B=20

Output: 5,7

5,11

5,13

7,11

5,17

5,19

7,13

I hope this will be enough to clear your doubt!

[REMEMBER ABOUT THE PAIRS CHECKING I CAN BE WRONG ALSO IN SAYING THAT 7,11 WILL COME BEFORE 5,17 DEPENDS ON ITS PAIR VALUE, OTHER THEN THE LOGIC IS CLEAR AND SIMPLE.]

KEEP CODING GUYS.