/ Published in: Python
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
#!/usr/bin/python print "\nProject Euler - Problem 10" print "Find the sum of all primes below two million." # Primes are divisible only by themselves n = 2000000 nums = range(0,n) sqrt = int(n ** 0.5) a = [] a.append(1) for x in range(1,n+1): a.append(1) for m in range(2,sqrt): if a[m] == 1: k = m*m while k <= n: a[k] = 0 k += m x= sum([i*j for i,j in zip(a,nums)]) print x