Skip to content

Instantly share code, notes, and snippets.

@bnlucas
bnlucas / miller_rabin.py
Last active April 11, 2024 16:43
Miller-Rabin primality testing with Python.
def miller_rabin(n, k=10):
if n == 2:
return True
if not n & 1:
return False
def check(a, s, d, n):
x = pow(a, d, n)
if x == 1:
return True