I am getting TLE can you see how to fix it?
inside while loop you have another loop
for(int i=a;i<=b;i++)
{
if(p[i]==1)
{
count++;
}
}
which is increasing time complexity
you can avoid this loop by making a prefix sum array
and can find ans in O(1) time for each query
this will help you to get rid of TLE
you code has many mistakes
-
your prime function is not correct
you write i instead j in inner loop -
instead of int use long long int
-
make bool p array not int
because in p array you have to store only 0 and 1 -
to reduce time complexity if you put the loop inside loop then i will not work
you have to make loop outside
i have done some changes you can see them in code below
Modified Code