I am getting TLE for the last sub task of this
I also have a couple of doubts.

If I am finding primes upto 10^3 or 10^4 I am getting WA for last two sub tasks. I think I should get AC for that.

If I replace all[j]<=arr[i] with all[j]*all[j]<=arr[i], I am getting WA for last two sub tasks. Shouldn’t this be right? I mean shouldn’t we check it up to square root of the number?

And finally, what can be done to improve my solution?