This repository has been archived on 2025-05-08. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
python-oneliners/PrimeTest/primetest_one_line.py

1 line
426 B
Python

primetest = lambda n, r=15: n == 2 if n < 3 else n % 2 != 0 and [all((not (lambda a: pow(a, d, n) != 1 and not any(map(lambda i: pow(a, 2 ** i * d, n) == n - 1, range(s))))(random(2, n - 1)) for _ in range(N))) for s, d, random, N in [(*[list(iter(lambda: sd[1] % 2 == 1 or sd.__setitem__(0, sd[0] + 1) or sd.__setitem__(1, sd[1] // 2), True)) and False or sd for sd in [[0, n - 1]]][0], __import__("random").randint, r)]][0]