Optimizations for prime counting