mirror of
https://hub.njuu.cf/TheAlgorithms/Python.git
synced 2023-10-11 13:06:12 +08:00
Optimized prime check code in Python.
This commit is contained in:
parent
4e0184a41d
commit
2040757751
@ -1,12 +1,8 @@
|
||||
import math
|
||||
def primeCheck(number):
|
||||
prime = True
|
||||
for i in range(2, int(number**(0.5)+1), 2):
|
||||
if i != 2:
|
||||
i = i - 1
|
||||
if number % i == 0:
|
||||
prime = False
|
||||
break
|
||||
return prime
|
||||
if n % 2 == 0 and n > 2:
|
||||
return False
|
||||
return all(n % i for i in range(3, int(math.sqrt(n)) + 1, 2))
|
||||
|
||||
def main():
|
||||
print(primeCheck(37))
|
||||
|
Loading…
Reference in New Issue
Block a user