Last active
September 27, 2015 04:15
-
-
Save markroxor/03f3a504520c69119a9d to your computer and use it in GitHub Desktop.
Generate Primes below 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
from sys import stdin | |
nex = iter(map(int,stdin.read().split())).__next__ | |
def markMultiples(vis,k): | |
i = 2 | |
num=i*k | |
while num <= len(vis): | |
vis[num-1] = 1 | |
i+=1 | |
num=i*k | |
def SeiveOfEratosthenes(n): | |
counti=0 | |
if(n>1): | |
vis=[0]*n | |
for i in range(1,n): | |
if not vis[i]: | |
counti+=1 | |
markMultiples(vis,i+1) | |
return counti | |
lis = [] | |
for i in range(42): | |
if(i<4): | |
lis.append(1) | |
else: | |
lis.append(lis[i-1]+lis[i-4]) | |
t = nex() | |
for i in range(t): | |
print (SeiveOfEratosthenes(lis[nex()])) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment