Created
January 31, 2021 12:57
-
-
Save ashutoshkrris/35e2fcebf31883b9246793321d46f00f to your computer and use it in GitHub Desktop.
Prime Numbers using Sieve of Eratosthenes in Python
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 seive_of_eratosthenes(n): | |
| is_prime = [True for _ in range(n+1)] | |
| is_prime[0], is_prime[1] = False, False | |
| for i in range(2, int(n**0.5)+1): | |
| for j in range(2*i, n+1, i): | |
| is_prime[j] = False | |
| return is_prime | |
| if __name__ == "__main__": | |
| n = int(input("Enter the number upto which : ")) | |
| li = seive_of_eratosthenes(n) | |
| for i in range(n+1): | |
| if li[i]: | |
| print(i, end=" ") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment