

Link: http://codepad.org/jzSbO7BA raw code | fork ]



Python , pasted on Aug 21:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 import time start = time . time () def sievesum ( end ): array = range ( 2 , end ) primality = [ True for x in array ] p = 2 while p < end : for x in range ( p , len ( array )): if primality [ x ] == False : continue elif array [ x ] % p == 0 and array [ x ] > p : primality [ x ] = False ##print array[x], primality[x], ' \t\t', p # diagnostic i = p - 1 while primality [ i ] != True : i += 1 p += i ##print # formatting primes = [] for x in range ( len ( primality )): if primality [ x ] == True : primes . append ( array [ x ]) ##print primes[-1] # for testing sum = 0 for x in primes : sum += x return sum print sievesum ( 2000000 ) end = time . time () - start print "

==========

(" + str ( end ) + "s)"