Pure Programmer
Blue Matrix

Cluster Map

Project: Number of Primes (Estimate)

The number of primes equal to or less than a number x is denoted by the function `π(x)`. There is no easy way to compute this function although there are ways to estimate it. Write a function `π(x)` that uses the estimate formula `x/(ln x - 1)`. Assert that values of x must be greater to or equal to 100. Write a test program to print the estimated values of `π(x)` for x that are powers of 10 from `10^2` up to `10^9`. How does this approach compare to the actual value of `π(x)`?

See [[How Many Primes Are There?]]

$ g++ -std=c++17 NumberOfPrimesEstimate.cpp -o NumberOfPrimesEstimate -lfmt $ ./NumberOfPrimesEstimate π(100) = 28 π(1000) = 169 π(10000) = 1218 π(100000) = 9512 π(1000000) = 78030 π(10000000) = 661459 π(100000000) = 5740304 π(1000000000) = 50701542