Last active
October 2, 2022 11:55
-
-
Save SanjarbekSaminjonov/a344d88a7ada86919c15d3ddebfcf3de to your computer and use it in GitHub Desktop.
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
import math | |
import time | |
def is_prime(number: int, prime_numbers: list) -> bool: | |
if number < 2: | |
return False | |
root_of_number = int(math.sqrt(number)) | |
for devider in prime_numbers: | |
if devider > root_of_number: | |
return True | |
if number % devider == 0: | |
return False | |
return True | |
def get_prime_numbers(to: int) -> list: | |
prime_numbers = list() | |
for number in range(1, to + 1): | |
if is_prime(number, prime_numbers): | |
prime_numbers.append(number) | |
return prime_numbers | |
if __name__ == '__main__': | |
start_time = time.time() | |
print(get_prime_numbers(100000)) | |
end_time = time.time() | |
print(f'--- {end_time - start_time} seconds ---') | |
# by Sanjarbek Saminjonov |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bu yer comment uchun 🤔