Test approximations of the prime counting function - MATLAB Cody - MATLAB Central

Problem 46117. Test approximations of the prime counting function

Difficulty:Rate
Cody Problem 241, which is based on Project Euler Problem 7, asks us to identify the Nth prime number. That is, the problem seeks the inverse of the prime counting function pi(n), which provides the number of primes less than or equal to n. The Prime Number Theorem gives approximate forms of pi(n) for large n. Two such approximations are n/ln(n) and the offset logarithmic integral Li(n) = li(n) - li(2), where li(x) = integral of 1/ln(t) from t = 0 to t = infinity (See Cody Problem 46066).
Test these approximations by computing two ratios: r1 = [n/ln(n)]/pi(n) and r2 = Li(n)/pi(n). Do not round the approximations to integers. For n = 100, you will find that the first approximation is about 13% low and the second is about 16% high. However, for n = 10^8, the first approximation is 6% low and the second is only 0.01% high.

Solution Stats

61.29% Correct | 38.71% Incorrect
Last Solution submitted on Sep 09, 2024

Problem Comments

Solution Comments

Show comments
R2025a Pre-release highlights
This topic is for discussing highlights to the current R2025a Pre-release.
18
8

Problem Recent Solvers15

Suggested Problems

More from this Author291

Problem Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Go to top of page