とりあえずやってみた
def get_prime_list(max): prime_list = [2] for num in range(3, max + 1): if not num % 2 == 0: for odd in range(3, num): if num % odd == 0: break else: prime_list.append(num) return prime_list def product_of_prime(prime_list, max=100): result_list = [] prime_list_copy = prime_list[:] for p01 in prime_list: for p02 in prime_list_copy: product = p01 * p02 if max < product: break result_list.append(product) prime_list_copy = prime_list_copy[1:] result_list = list(set(result_list)) result_list.sort() return result_list if __name__ == '__main__': p = get_prime_list(100) print product_of_prime(p)
実行結果
[4, 6, 9, 10, 14, 15, 21, 22, 25, 26, 33, 34, 35, 38, 39, 46, 49, 51, 55, 57, 58, 62, 65, 69, 74, 77, 82, 85, 86, 87, 91, 93, 94, 95]
これ合ってるの?(´・ω・`)