Skip to content

Instantly share code, notes, and snippets.

@aldente39
Created December 20, 2011 00:05
Show Gist options
  • Save aldente39/1499519 to your computer and use it in GitHub Desktop.
Save aldente39/1499519 to your computer and use it in GitHub Desktop.
The sum of prime progression (Parallel)
from multiprocessing import Pool
import time
def isPrime(n):
if n < 2:
return 0
if n == 2:
return n
if n % 2 == 0:
return 0
i = 3
while i * i <= n:
if n % i == 0:
return 0
i += 2
return n
#http://d.hatena.ne.jp/hagaeru3sei/20081029
def main():
l = []
ans = 0
p = Pool(4)
print sum(p.map(isPrime, range(2000000)))
if __name__ == '__main__':
s = time.time()
main()
print 'time: %f' % (time.time() - s)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment