Problem 46117. Test approximations of the prime counting function
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  , which provides the number of primes less than or equal to n. The Prime Number Theorem gives approximate forms of
, which provides the number of primes less than or equal to n. The Prime Number Theorem gives approximate forms of  for large n. Two such approximations are
 for large n. Two such approximations are  and the offset logarithmic integral
 and the offset logarithmic integral  , where
, where  (See Cody Problem 46066).
 (See Cody Problem 46066).
Test these approximations by computing two ratios: ![r1 = [n/ln(n)]/pi(n)](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQAAAAAoCAYAAAAR+iSJAAAGTElEQVR4nO2d8ZGyMBDFXw90YAM2YAVWYAd2YAe2YA2WYA/XgjXYgt8f+D4XJGQ3gRB0fzPM3A0HJJvNyyZZOMBxHMdxHMdxHOenaADsAkezQFk2hZ+5JuZqq03m9c6K2QF4Bo5d4bKcANwKPzOFDaYTKovozdVWN7S2L81SdnQEdKoauAM4LF2ICFu0HWaqEbMBcEVevXMEYPO6vnTnqdGOP0ktArBFWw6NQzQA9gAuAB6va0swtdNK/pDuvDkCcHw9uyS12vEnqUUALmgVPMYRrfPI8LeEAGwwr9g0aCOglPvnCMAdrU1LUbMdf5JaBOABm3JfUFYA/jD/PHmP1nmtI2OqADDqKhn+12zHn6QGAdijFQALJ5QTgAPa8pVwqBuAs/GaVAE4Qxd1TUXtdvxJahCAy+uwUFIA7ii3Sn6AfVROFYDSi6612/EnWVoAGqQ5cCkBWMKRHrB1lBT7MeoqFSavwY4/ydICcEA7MljRCMAWXQfg7ye0HUDDNbF8OVifmSIAKVFXDmuw4wcbtIY94a1cDdpV0xO+Y5HBKgDMRjuiW3/ZuSx2SZ2rhQRg97rf/XWOo1x/5+CpfO4Tto6yRSsuUmAatEKnFR7WTTtaWgWgQWsXrQhy2/WkOEL3XIMd/9PfaqITbV8/WxxIC4Um97BWViMA7EDsVE+8lZUJGLJjafeVc5JQQgKwxXuriW3HHYZmoLxjHYe2iYWRQ1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kaf4/hxfBhk6tgivpRwj18dCyVC55fNC8OUxzcr1BfZ965gAWKMutmfIJrRhyhuINdsxm28VgKlISUKpAevbc6mkfqJrTAAYWtfwjbza7ZiNC0CYxRplIkp8Zy5VIMcEgOm0tVCzHbNxAQhT+vtzc3DEfHU4Iz03YkwAaoy6arVjNi4AYaxJKLVyxPQONrZtqiEkAEv90w8NNdoxC7nyXMN8S0t/xVwe1kWeEKW/Pzc3e0xnmw30I7S1rc6o+1+tLWXHyRn6XNJUFZubEv8cdIrUX8feVt8SdTkr54x1RUXfwhXfE3U5juM4juM4juM4juM4juM4juMY+Afhj6HXww+3bQAAAABJRU5ErkJggg==) and
 and  . Do not round the approximations to integers. For
. Do not round the approximations to integers. For  , you will find that the first approximation is about 13% low and the second is about 16% high. However, for
, you will find that the first approximation is about 13% low and the second is about 16% high. However, for  , the first approximation is 6% low and the second is only 0.01% high.
, the first approximation is 6% low and the second is only 0.01% high. 
Solution Stats
Problem Comments
Solution Comments
Show commentsProblem Recent Solvers16
Suggested Problems
- 
         The Goldbach Conjecture, Part 2 2385 Solvers 
- 
         
         582 Solvers 
- 
         
         101 Solvers 
- 
         Join Strings with Multiple Different Delimiters 214 Solvers 
- 
         
         73 Solvers 
More from this Author314
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!