自问了这个问题之后,我围绕C
++库primesieve编写了Python包装器。https://github.com/hickford/primesieve-
python
>>> from primesieve import *# Generate a list of the primes below 40>>> generate_primes(40)[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37]# Generate a list of the primes between 100 and 120>>> generate_primes(100, 120)[101, 103, 107, 109, 113]# Generate a list of the first 10 primes>>> generate_n_primes(10)[2, 3, 5, 7, 11, 13, 17, 19, 23, 29]# Generate a list of the first 10 starting at 1000>>> generate_n_primes(10, 1000)[1009, 1013, 1019, 1021, 1031, 1033, 1039, 1049, 1051, 1061]# Get the 10th prime>>> nth_prime(10)29# Count the primes below 10**9>>> count_primes(10**9)50847534