I have been using this code to check if a number is prime or not:
def pcheck(number):
if number < 2:
k = "NO"
# theres no prime number less than 2
else:
i = 2
factors = []
while i * i <= number:
if number % i:
i += 1
else:
number //= i
factors.append(i)
if number > 1:
factors.append(n)
# get the factors of the number, a prime number will only have 1 factor, not including 1
if len(factors) == 1:
k = "YES"
else:
k = "NO"
return k
n = int(input())
print(pcheck(n))
But even with modifcations it would still struggle with number that have 18 digit, this is rather troublesome for me as i cant use it in this case. I have heard but rabin miller test but have never been able to implement it in to my code. Is there a more efficient way to check prime with large numbers but still is as fast as possible?