Rubyで書いてみました。答えを順番に探して加えていく単純な方法です。 require 'prime' N = 70 mark = {} ary = [] Prime.each(N){|i| # 素数iで初めて割り切れる数をtmpに加えていく tmp = [] i.step(N, i){|j| if mark[j] == nil tmp.push(j) mark[j] = 1 end } # 次数が低い順にaryに加える f_ary, b_ary = tmp, [] j = i * i while f_ary.size > 0 f_ary.each{|k| k % j == 0 ? b_ary.push(k) : ary.push(k)} f_ary, b_ary = b_ary, [] j *= i end } p ary 出力結果 [2, 6, 10, 14, 18, 22, 26, 30, 34, 38, 42, 46, 50, 54, 58, 62, 66, 70, 4, 12, 20 , 28, 36, 44, 52, 60, 68, 8, 24, 40, 56, 16, 48, 32, 64, 3, 15, 21, 33, 39, 51, 57, 69, 9, 45, 63, 27, 5, 35, 55, 65, 25, 7, 49, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67]