{"id":26,"date":"2013-08-13T19:35:00","date_gmt":"2013-08-13T19:35:00","guid":{"rendered":"https:\/\/www.root42.de\/blog\/?p=26"},"modified":"2013-08-13T19:35:00","modified_gmt":"2013-08-13T19:35:00","slug":"there-are-approximately-nlnn-primes-between-n-and-2n","status":"publish","type":"post","link":"https:\/\/www.root42.de\/blog\/?p=26","title":{"rendered":"There are approximately N\/ln(N) primes between N and 2N"},"content":{"rendered":"<p>Just saw <a href=\"http:\/\/www.youtube.com\/watch?v=l8ezziaEeNE\">this very nice video<\/a> by <a href=\"https:\/\/twitter.com\/numberphile\">@numberphile<\/a>, and thought I whip up a small Python program to demonstrate the prime number theorem: <\/p>\n<pre><br \/>#!\/usr\/bin\/env python<br \/>#<br \/># \"Chebyshev said it, and I say it again: There's always a prime between n and 2n.\"<br \/>#<br \/><br \/>import sys<br \/>import math<br \/><br \/>class PrimeFinder:<br \/><br \/>    def __init__( self, n ):<br \/>        self.n = n<br \/>    <br \/>    def isNPrime( self, N ):<br \/>        for x in range( 2, int( math.sqrt( N ) ) + 1 ):<br \/>            if N % x == 0:<br \/>                return False<br \/>        return True<br \/><br \/>    def computeAllPrimesBetweenNAndTwoN( self ):<br \/>        result = []<br \/>        for N in range( self.n, 2 * self.n + 1 ):<br \/>            if self.isNPrime( N ):<br \/>                result = result + [ N ]<br \/>        return result<br \/><br \/>def main():<br \/>    if len( sys.argv ) != 2:<br \/>        print \"Prints all prime numbers between N and 2N\"<br \/>        print \"Usage: %s N\" % sys.argv[ 0 ]<br \/>        print \"Where N is some positive, natural number.\"<br \/>        sys.exit( 0 )<br \/><br \/>    N = int( sys.argv[ 1 ] )<br \/>    primeFinder = PrimeFinder( N )<br \/>    allPrimes = primeFinder.computeAllPrimesBetweenNAndTwoN()<br \/>    print \"There are %u primes between %u and %u: %s\" % ( <br \/>        len( allPrimes ), N, 2 * N, str( allPrimes )[ 1 : -1 ] <br \/>    )<br \/><br \/>if __name__ == \"__main__\":<br \/>    main()<br \/><\/pre>\n<p> And it seems to work, but check <a href=\"http:\/\/wolfr.am\/17LMVLl\">WolframAlpha<\/a> if you don&#8217;t trust me \ud83d\ude42  <\/p>\n<pre><br \/>$ .\/myprimes.py 100000<br \/>There are 8392 primes between 100000 and 200000: 100003, 100019, 100043 ...<br \/><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Just saw this very nice video by @numberphile, and thought I whip up a small Python program to demonstrate the prime number theorem: #!\/usr\/bin\/env python## &#8220;Chebyshev said it, and I say it again: There&#8217;s always a prime between n and 2n.&#8221;#import sysimport mathclass PrimeFinder: def __init__( self, n ): self.n = n def isNPrime( self, &hellip; <a href=\"https:\/\/www.root42.de\/blog\/?p=26\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;There are approximately N\/ln(N) primes between N and 2N&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[7,26,15],"tags":[],"_links":{"self":[{"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=\/wp\/v2\/posts\/26"}],"collection":[{"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=26"}],"version-history":[{"count":0,"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=\/wp\/v2\/posts\/26\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=26"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=26"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=26"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}