A script for printing and/or counting prime numbers.
The script calculates primes using the sieve of eratosthenes and count how many there are. It displays the number of Mersenne, Twin, Cousin, Sexy and Pythagorean primes.
This script is ready to use script which uses two arguments to run. The first argument decides what will be displayed and the second decides the upper bound for the search (including that number).
This script require the time, math, sys and doctest package.
$ git clone https://github.com/StokicDusan/CountPrimes.git
$ cd CountPrimes/
In the command line simply invoke the script with two arguments:
$ python countPrimes.py argv1 argv2
-
argv1:
argv1 Value print primes 1 count primes 2 print and count primes 3 -
argv2:
Any positive integer
Invoking the script with no or less arguments will run testmod().
The following code block shows examples of calling the countPrimes script from terminal.
$ python3 countPrimes.py 1 1
$ python3 countPrimes.py 1 17
2 3 5 7 11 13 17
$ python3 countPrimes.py 1 25
2 3 5 7 11 13 17 19 23
$ python3 countPrimes.py 2 1000000
There are 78,498 Primes!!!!
7.850% are Primes
There are 7 Mersenne Primes { Mp=2**p-1 }: 3 7 31 127 8191 131071 524287
There are 5 Euclid Primes { Ep=pn#+1 }: 3 7 31 211 2311
There are 8,169 Twin Primes
There are 8,144 Cousin Primes
There are 16,386 Sexy Primes
There are 39,175 Pythagorean Primes { Pp=4n+1 }
Elapsed: 0.616262 seconds
$ python3 countPrimes.py 3 31
2 3 5 7 11 13 17 19 23 29 31
There are 11 Primes!!!!
34.375% are Primes
There are 3 Mersenne Primes { Mp=2**p-1 }: 3 7 31
There are 3 Euclid Primes { Ep=pn#+1 }: 3 7 31
There are 5 Twin Primes
There are 4 Cousin Primes
There are 6 Sexy Primes
There are 4 Pythagorean Primes { Pp=4n+1 }
Elapsed: 5.6e-05 seconds
If you encounter any bugs or have suggestions, please file an issue in the Issues section of the project.