Skip to content

Commit a6fa433

Browse files
committed
Add optional round parameter for primetest
1 parent ad52c3a commit a6fa433

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

PrimeTest/primetest.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def try_comp(a, d, n, s):
1010
return True
1111

1212

13-
def primetest(n):
13+
def primetest(n, r=15):
1414
if n < 3: return n == 2
1515
if n % 2 == 0: return False
1616
s, d = 0, n - 1
@@ -20,7 +20,7 @@ def primetest(n):
2020
break
2121
s, d = s + 1, quo
2222

23-
for i in range(15):
23+
for i in range(r):
2424
if try_comp(random.randrange(2, n), d, n, s):
2525
return False
2626
return True

PrimeTest/primetest_lambda.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# quorem = lambda n: [list(iter(lambda: sd[1] % 2 == 1 or sd.__setitem__(0, sd[0] + 1) or sd.__setitem__(1, sd[1] // 2),
44
# True)) and False or tuple(sd) for sd in [[0, n - 1]]][0]
55

6-
primetest = lambda n: 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, 15)]][0]
6+
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]
77

88
print(primetest(16826274250898468911280407749426542060694768486649616295792750595928899095760198861413145674011622196806001189975331140430984389138737798839798102100501250562384543970148324519320707086782480622768727739619400406298163697633506711667490859272493284358461677857576459592581649298303621108919528607436653031634208416252311924449922771895182310841019584155318547423916714195019363678142800559476884532645915293106647126449661258738488043253150745449466402688849719911594517744984668897073482226741417140010936686564467276499458185350171327208056715254738641774818774823242004784520937289671279357019604426730692283732729))
99
print(primetest(2938475483920938745789028764))

PrimeTest/primetest_one_line.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
primetest = lambda n: 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, 15)]][0]
1+
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]

0 commit comments

Comments
 (0)