Created
June 18, 2020 09:32
-
-
Save pknowledge/072e64fd7ebc8cec5162d0907c054e22 to your computer and use it in GitHub Desktop.
Sieve of Eratosthenes | Competitive Programming with Python https://youtu.be/-wIYdmPiHcA
This file contains 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
from math import * | |
def genprimes(n): | |
primes = [True]*(n+1) | |
primes[0] = False | |
primes[1] = False | |
for p in range(2,int(sqrt(n))+1): | |
if primes[p] == True: | |
for i in range(p*p,n+1,p): | |
primes[i] = False | |
for i in range(0,len(primes)): | |
if primes[i] == True: | |
print(i,end=" ") | |
t = int(input()) | |
while t: | |
n = int(input()) | |
genprimes(n) | |
t=t-1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment