read the problem again. time limit is 6 sec and maximum limit of numbers is 1 <= m <= n <= 1000000000. By your code u cant get results in this time limit.
Solution : use an array of prime numbers starting from 2 to 32117(as i used it, copy it from sumwhere) and compare the numbers with the array to get result.
2nd problem : no need of storing all inputs at once in an array.
solution : just use two int variables, run a loop for t test cases, get the inputs in each case and print result. then again take inputs for next case.