Failed two test cases

my code: https://ide.codingblocks.com/s/243687

@princeky4
you are required to take ith prime for ith iteration like for i=1, it is 2, for i=2 it is 3.

for (int i = r+1; i <= (b+1); i++) { 
	if (isPrime(i)) 	
       r = i;
       break;
} 

But in above portion of your code, you are checking for ith prime in the range of b+1. which doesn’t mean anything. It is something like you are trying to find 5th prime number in between 1 to 6.

Precompute with the help of prime seive which will be better and easy way.

Also the outer i loop is from to 0 to a which if i getting your code correctly then should be from 1 to b.

Please go through the problem statement again and understand it with help of example. Then try it again.

Let me know when you are able to understand the problem and want help in writing code then i can share my code with you.

modified code: https://ide.codingblocks.com/s/243687 now it failed one teat case

i solved it thank you

1 Like