How to find BIG prime numbers
If my calculations are right the best way to find a BIG prime number is to iterate through all the prime numbers before it, why? Because the quickest way to check a prime is to see if it is divisible by all the previous primes, I am not going to waste any processing power on non prime can be defined with prime numbers like 63 = 7*3^2.
So here is my first attempt to find that BIG prime. (With BIG prime a mean a 100 digit number)
The code below is my first prototype, I still need to save the prime that I found on a DB so that I don’t need to start from 1 all the time I start the code:
# Python program to calculate prime numbers
import math
import numpy
import sqlite3
primeList = [2,3, 5, 7, 11, 13, 17, 19, 23, 29 ]
def isPrime(num):
# prime numbers are greater than 1
if num > 1:
# check for factors
for i in range(len(primeList)):
if (num % primeList[i]) == 0:
#print(num,"is not a prime number")
#print(i,"times",num//i,"is",num)
break
else:
print(num,"is a prime number")
primeList.append(num)
#add_prime(num)
# if input number is less than
# or equal to 1, it is not prime
else:
print(num,"is not a prime number")
num = 30
while True:
isPrime(num)
num = num +1
if num == math.pow(10, 101):
break
Below are more posts about Prime numbers.
- Prime number 2. The sqlite strikes back! In this post I add sql so that I can stop and and restart where I left.
- Multi Threading and still looking for Primes. In this post I make the most of my laptop processing power.
- Sieve Of Eratosthenes (Still on Prime). The quickest way to find a 8 digit prime number.