結果

問題 No.1058 素敵な数
ユーザー ThetaTheta
提出日時 2022-10-19 11:49:13
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 23 ms / 2,000 ms
コード長 1,481 bytes
コンパイル時間 192 ms
コンパイル使用メモリ 10,936 KB
実行使用メモリ 8,420 KB
最終ジャッジ日時 2023-09-12 01:37:37
合計ジャッジ時間 1,264 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 23 ms
8,040 KB
testcase_01 AC 22 ms
8,420 KB
testcase_02 AC 22 ms
8,420 KB
testcase_03 AC 22 ms
8,420 KB
testcase_04 AC 22 ms
8,416 KB
testcase_05 AC 23 ms
8,416 KB
testcase_06 AC 22 ms
8,316 KB
testcase_07 AC 23 ms
8,260 KB
testcase_08 AC 23 ms
8,340 KB
testcase_09 AC 23 ms
8,332 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import inf, sqrt, ceil


def is_prime(num: int) -> bool:
    for candidate in range(2, ceil(sqrt(num))):
        if num % candidate == 0:
            return False
    else:
        return True


def main():
    N = int(input())
    prime_over_10000 = []
    for number in range(100001, 103000):
        if is_prime(number):
            prime_over_10000.append(number)

    match N:
        case 1:
            print(1)
        case 2:
            print(prime_over_10000[0]**2)
        case 3:
            print(prime_over_10000[0]*prime_over_10000[1])
        case _:
            current_first_idx = [0, 1]
            current_second_idx = [2, 1]

            for _ in range(4, N+1):
                now_number = inf
                now_index = None
                for idx, (first, second) in enumerate(zip(
                        current_first_idx, current_second_idx)):
                    if prime_over_10000[first] * prime_over_10000[second] < now_number:
                        now_number = prime_over_10000[first] * \
                            prime_over_10000[second]
                        now_index = idx

                if current_second_idx[now_index] not in current_first_idx:
                    current_first_idx.append(current_second_idx[now_index])
                    current_second_idx.append(current_second_idx[now_index])
                current_second_idx[now_index] += 1

            print(now_number)


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