素数テーブル

Share:
 1func newPrimeTable(n int) []bool {
 2	pt := make([]bool, n+1)
 3	for i := 2; i <= n; i++ {
 4		pt[i] = true
 5	}
 6	for m := 2; m*m <= n; m++ {
 7		if !pt[m] {
 8			continue
 9		}
10		for i := m * m; i <= n; i += m {
11			pt[i] = false
12		}
13	}
14	return pt
15}
16