isPrime() function/algo optimization:
insted of taking all integers from 2 to K, take only odds since we know that the even prime is 2. This should in theory reduce the time to check primilaty to half.
This commit is contained in:
parent
1954308cb4
commit
db2a852cf3
4
rsa.py
4
rsa.py
@ -112,8 +112,8 @@ def isPrime(number):
|
|||||||
|
|
||||||
#Take odd D such that 1 < D <= K
|
#Take odd D such that 1 < D <= K
|
||||||
#If D devides number then number is not prime. otherwise prime.
|
#If D devides number then number is not prime. otherwise prime.
|
||||||
for D in range(2, K):
|
for D in range(1, K, 2):
|
||||||
if D % 2 == 0:
|
if D % 2 == 0 or D == 1:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
if number % D == 0 or number % 5 == 0:
|
if number % D == 0 or number % 5 == 0:
|
||||||
|
Loading…
Reference in New Issue
Block a user