link to my code
TLE in case 0, rest cases are passed
Hey @jatin111
here’s my suggestion to you. While doing these kinds of questions try to minimize the redundant operations.
Here it is calculating primes.
Think if T is like 10^4 and n is 10^6 and in worst case each of the test cases has very large value so you will be computing primes again and again and that will give you a TLE.
So precompute the primes once upto the given constraints, you will be good to go
correct code : https://ide.codingblocks.com/s/283433
yes,understood. Thanks