My code is showing tle
@mayank10
Yes there a number of mistakes in your code.
You did not print ā\nā after answer of each query.
It will show TLE because your complexity is Q*N which will not get Accepted.
Try to calculate the answer of every possible query beforehand, something similar to Sieve of Eratosthenes.
@mayank10 I made some changes in your code. you can refer to it later on.
but please try yourself before opening the code.
Keep the prime seive in mind.