mirror of
https://github.com/kuhyx/WUT_Computer_Science.git
synced 2026-07-06 19:23:07 +02:00
Add comments
This commit is contained in:
parent
76679fab60
commit
e223357afe
@ -11,14 +11,16 @@ def sieve_of_eratosthenes(num: int) -> list[int]:
|
|||||||
Returns:
|
Returns:
|
||||||
list[int]: List of prime numbers
|
list[int]: List of prime numbers
|
||||||
"""
|
"""
|
||||||
# boolean list
|
# boolean list to store if a number is prime or not
|
||||||
prime = [True] * (num+1)
|
prime = [True] * (num+1)
|
||||||
p = 2
|
p = 2 # starting prime number
|
||||||
|
# we will iterate till square root of num because
|
||||||
|
# if a number is not prime then it will have a factor less than or equal to square root of that number
|
||||||
while p <= math.sqrt(num):
|
while p <= math.sqrt(num):
|
||||||
# If prime[p] is not
|
# If prime[p] is not
|
||||||
# changed, then it is a prime
|
# changed, then it is a prime
|
||||||
if prime[p]:
|
if prime[p]:
|
||||||
i = (p << 1)
|
i = (p << 1) # i = p * 2
|
||||||
# Updating all multiples of p
|
# Updating all multiples of p
|
||||||
while i <= num:
|
while i <= num:
|
||||||
prime[i] = False
|
prime[i] = False
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user