Skip to content

Instantly share code, notes, and snippets.

@tomrockdsouza
Last active August 10, 2024 22:06
Show Gist options
  • Save tomrockdsouza/347367de2b587a3535eea77d8f654795 to your computer and use it in GitHub Desktop.
Save tomrockdsouza/347367de2b587a3535eea77d8f654795 to your computer and use it in GitHub Desktop.
'''
Most efficient algorithm in python
Get prime numbers upto a given number.
By Tomrock D'souza
'''
from numba import jit
from time import time
@jit(nopython=True)
def find_primes_upto(a):
sieve = [True] * (a + 1)
sieve[0] = sieve[1] = False
for i in range(2, int((a) ** 0.5) + 1):
if sieve[i]:
for m in range(i * i,a + 1, i):
sieve[m] = False
return [i for i in range(a + 1) if sieve[i]]
if __name__ == '__main__':
num = int(input())
start = time()
print(len(a:=find_primes_upto(num)))
print(time() - start)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment