From e223357afe71e916d86d2360f0a7d8a89a19c290 Mon Sep 17 00:00:00 2001 From: Normale <52136684+Normale@users.noreply.github.com> Date: Fri, 25 Nov 2022 23:56:20 +0100 Subject: [PATCH] Add comments --- code/project.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/code/project.py b/code/project.py index f89dca06..85447344 100644 --- a/code/project.py +++ b/code/project.py @@ -11,14 +11,16 @@ def sieve_of_eratosthenes(num: int) -> list[int]: Returns: list[int]: List of prime numbers """ - # boolean list + # boolean list to store if a number is prime or not 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): # If prime[p] is not # changed, then it is a prime if prime[p]: - i = (p << 1) + i = (p << 1) # i = p * 2 # Updating all multiples of p while i <= num: prime[i] = False