Skip to content

Instantly share code, notes, and snippets.

@ami-GS
Last active August 29, 2015 13:56
Show Gist options
  • Save ami-GS/8841037 to your computer and use it in GitHub Desktop.
Save ami-GS/8841037 to your computer and use it in GitHub Desktop.
Nまでの素数のリストを出力
import sys
import time
s = time.time()
N = int(sys.argv[1])
prime = [1]*N
prime[0] = 0
prime[1] = 0
for i in range(2, int(N**0.5)):
if prime[i]:
for j in range(i*2, N, i):
prime[j] = 0
ans = [i for i in range(N) if prime[i]]
print ans, len(ans), time.time()-s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment