We present an efficient and elementary algorithm for computing the number of primes up to in time, improving upon the existing combinatorial methods that require time. Our method has a similar time complexity to the analytical approach to prime counting, while avoiding complex analysis and the use of arbitrary precision complex numbers. While the most time-efficient version of our algorithm requires space, we present a continuous space-time trade-off, showing, e.g., how to reduce the space complexity to while slightly increasing the time complexity to . We apply our techniques to improve the state-of-the-art complexity of elementary algorithms for computing other number-theoretic functions, such as the the Mertens function (in time compared to the known ), summing Euler’s totient function, counting square-free numbers and summing primes. Implementation code is provided.

生成讲解博客的中文版本

生成AI智能校验的中文版本