Sieve Of Atkin Implementation in Python

后端 未结 2 1298
無奈伤痛
無奈伤痛 2020-12-11 05:12

I am trying to implement the algorithm of Sieve of Atkin given in Wikipedia Link as below:

Sieve Of Atkin

What I\'ve tried so far is the implementation in Py

2条回答
  •  不思量自难忘°
    2020-12-11 05:38

    You problem is that your limit is 100, but your is_prime list only has limit-5 elements in it due to being initialized with range(5, limit).

    Since this code assumes it can access up to limit index, you need to have limit+1 elements in it: is_prime = [False] * (limit + 1)

    Note that it doesn't matter that 4x^2+y^2 is greater than limit because it always checks n <= limit.

提交回复
热议问题