Open Source Your Knowledge, Become a Contributor
Technology knowledge has to be shared and made accessible for free. Join the movement.
def sieve(n: int) -> list:
Sieve away and only primes are left.
primes = 2*[False] + (n-1)*[True]
for i in range(2, int(n**0.5+1.5)):
for j in range(i*i, n+1, i):
primes[j] = False
return [prime for prime, checked in enumerate(primes) if checked]
if __name__ == '__main__':
Enter to Rename, Shift+Enter to Preview
Open Source Your Knowledge: become a Contributor and help others learn. Create New Content