Segmented prime sieve

for each prime in range 2 to sqrt(b) we are traversing from range a to b…will it not give TLE?..O(sqrt(b)*(b-a)) will be grater than power(10,10)?..bcoz sqrt(b) is order of power(10,5) and b-a is also order of power(10,5)…

But that traversal for each prime is very quick!

And you go to every number just once.

Lets take this : 2 3 4 5 6
2 -> 4->6
3 ->6
5

Thus we traversed once only.
If you dont traverese on even numbers, its more optimised. you won’t face TLE