categories: computer science
Hello everyone,
Below you will find a video with a detailed explanation of the Sieve of Eratosthenes algorithm. Its operation, time complexity, and usefulness. Below you will also find ready-made code to copy if needed.
Code:
przedzial = 10
tablica = [False, False] + [True] * (przedzial - 2)
for i in range(2, przedzial):
wielokrotnosc = 2
while wielokrotnosc * i < przedzial:
tablica[wielokrotnosc * i] = False
wielokrotnosc += 1 # increment the multiple
for i in range(len(tablica)):
print(str(i) + " " + str(tablica[i]))
Video:
Thank you for reading!
Read more