Last active
January 16, 2019 05:04
-
-
Save nitinbhojwani/47938464a193e3b54ebbaf8c5d47613c to your computer and use it in GitHub Desktop.
Prime Numbers till N
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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