How good is this result? In reality, there are 25 primes less than 100, but π(100) = 21.715. This is a difference of about 15%. But, the larger the value of n, the better the approximation gets. For instance π(1,000,000)=72,382, where in reality there are 78,498 primes less than one million. Now the difference is only 8%.

Why does this work? Honestly, I don't know. The mathematics are beyond me, but I think it has something to do with the Sieve of Eratosthenes method of finding prime numbers. I can't prove it, though.