Skip to content

Instantly share code, notes, and snippets.

@nitinbhojwani
Last active January 16, 2019 05:04
Show Gist options
  • Select an option

  • Save nitinbhojwani/47938464a193e3b54ebbaf8c5d47613c to your computer and use it in GitHub Desktop.

Select an option

Save nitinbhojwani/47938464a193e3b54ebbaf8c5d47613c to your computer and use it in GitHub Desktop.
Prime Numbers till N
def get_prime_numbers(n):
prime = [True for i in range(n+1)]
res = []
p = 2
while (p * p <= n):
# If prime[p] is not changed, then it is a prime
if (prime[p] == True):
res.append(i)
# Update all multiples of p
for i in range(p * p, n+1, p):
prime[i] = False
p += 1
return res
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment