Explanation needed for sum of prime below n numbers

Posted by Bala Krishnan on Stack Overflow See other posts from Stack Overflow or by Bala Krishnan
Published on 2013-06-25T04:06:02Z Indexed on 2013/06/25 4:21 UTC
Read the original article Hit count: 229

Filed under:
|
|

Today I solved a problem given in Project Euler its problem no 10 and it took 7 hrs for my python program to show the result. But in that forum itself a person named lassevk posted solution for this and it took only 4 sec. And its not possible for me to post this question in that forum because its not discussion forum. So, think about this if you want to mark this question as non-constructive.

marked = [0] * 2000000
value = 3
s = 2
while value < 2000000:
    if marked[value] == 0:
        s += value
        i = value
        while i < 2000000:
            marked[i] = 1
            i += value
    value += 2
print s

If any one understand this code please explain it simple as possible. Link to the Problem 10 question.

© Stack Overflow or respective owner

Related posts about python

Related posts about algorithm