結果
| 問題 |
No.1058 素敵な数
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-10-19 11:49:13 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 35 ms / 2,000 ms |
| コード長 | 1,481 bytes |
| コンパイル時間 | 94 ms |
| コンパイル使用メモリ | 12,672 KB |
| 実行使用メモリ | 10,880 KB |
| 最終ジャッジ日時 | 2024-06-29 14:47:37 |
| 合計ジャッジ時間 | 1,123 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 9 |
ソースコード
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()