I've seen many Python algorithms that check for primality, but I have found that they all fail when checking a particular number: 28430288029929701389
I've used this algorithm: What is the best algorithm for checking if a number is prime?
from __future__ import print_function
import sys
from sys import argv
def is_prime(n):
if n == 2:
return True
if n == 3:
return True
if n % 2 == 0:
return False
if n % 3 == 0:
return False
i = 5
w = 2
while i * i <= n:
if n % i == 0:
return False
i += w
w = 6 - w
return True
number_to_check = int(argv[1])
if is_prime(number_to_check):
print("%d is prime" % number_to_check)
else:
print("%d is not prime" % number_to_check)
and these algorithms: https://coderwall.com/p/utwriw/prime-numbers-with-python#comment_28424
and they all get into an endless loop when checking for primality of this particular number. I can check much bigger numbers and the result comes back instantly. Does anybody know if this is an issue with Python?