Created
December 5, 2023 08:27
-
-
Save KAnanev/57d8ba62c93e954f7e8204da45122663 to your computer and use it in GitHub Desktop.
prime in python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def eratoshenes_effective(num): | |
numbers = list(range(num + 1)) | |
numbers[0] = numbers[1] = False | |
for i in range(2, num): | |
if numbers[i]: | |
for j in range(i * i, num + 1, i): | |
numbers[j] = False | |
return numbers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def is_prime(num: int): | |
if num == 1: | |
return False | |
count = 2 | |
while count < num: | |
if num % count == 0: | |
return False | |
count += 1 | |
return True | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def is_prime(num): | |
if num == 1: | |
return False | |
count = 2 | |
while count * count <= num: | |
if num % count == 0: | |
return False | |
count += 1 | |
return True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment