1#Cach 1: Sang true false
2prime = [True] * (n+1)
3prime[0] = prime[1] = False
4for i in range(2, n+1):
5 if prime[i]:
6 for j in range(i*i, n+1, i):
7 prime[j] = False
8
9
10#Cach 2: Sang ra so
11prime = []
12m = []
13for i in range(2, n+1):
14 if i not in m:
15 prime.append(i)
16 for j in range(i*i, n+1, i):
17 m.append(j)
18