[ create a new paste ] login | about

Link: http://codepad.org/xU7eeK04    [ raw code | output | fork ]

swapnilghorpade - Python, pasted on Mar 4:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#sieve of euler
s=[]
t=[]
for i in xrange(30):
    s.append(i+2)
s.pop()
print s
j=0
i=s[j]
while i*i < 30:
    for k in s:
        l=k*i
        if l in s:
            t.append(l)
    for h in t:
        if h in s:
            s.remove(h)
    j=j+1
    i=s[j]
print s    


Output:
1
2
[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]
[2, 3, 5, 7, 11, 13, 17, 19, 23, 29]


Create a new paste based on this one


Comments: