結果

問題 No.1058 素敵な数
ユーザー はむ吉🐹はむ吉🐹
提出日時 2020-05-22 21:34:41
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,431 bytes
コンパイル時間 163 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 118,724 KB
最終ジャッジ日時 2024-04-15 16:11:03
合計ジャッジ時間 3,305 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
52,480 KB
testcase_01 AC 290 ms
118,344 KB
testcase_02 AC 269 ms
118,336 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3

import array
import itertools
import math


M = 10 ** 5 + 1


def segment_sieve(begin, end, typecode="L"):
    """Enumerates the prime numbers in [begin, end).
    :param int begin: The beginning of the interval.
    :param int end: The end of the interval.
    :param str typecode: The type of the array to be returned (optional).
    :return: The array of the prime numbers.
    :rtype: :class:`array.array`
    """
    assert begin > 1
    assert begin <= end
    sqrt_end = math.ceil(math.sqrt(end))
    is_prime_small = array.array("B", (True for i in range(sqrt_end)))
    is_prime_small[0] = False
    is_prime_small[1] = False
    is_prime = array.array("B", (True for i in range(end - begin)))
    for i in range(2, sqrt_end):
        if is_prime_small[i]:
            for j in range(2 * i, sqrt_end, i):
                is_prime_small[j] = False
            for k in range(max(2, (begin + i - 1) // i) * i, end, i):
                is_prime[k - begin] = False
    primes = array.array(typecode,
                         (i for i, cond in enumerate(is_prime, begin) if cond))
    return primes


def generate(n):
    if n <= 1:
        return 1
    primes = segment_sieve(M, (M * 9) // 8)
    prods = sorted(p * q for p, q in itertools.product(primes, repeat=2))
    return prods[n - 2]


def main():
    n = int(input())
    res = generate(n)
    print(res)


if __name__ == '__main__':
    main()
0