RosettaCodeData/Task/AKS-test-for-primes/Python/aks-test-for-primes-1.py
2019-09-12 10:33:56 -07:00

16 lines
343 B
Python

def expand_x_1(n):
# This version uses a generator and thus less computations
c =1
for i in range(n//2+1):
c = c*(n-i)//(i+1)
yield c
def aks(p):
if p==2:
return True
for i in expand_x_1(p):
if i % p:
# we stop without computing all possible solutions
return False
return True