結果

問題 No.2724 Coprime Game 1
ユーザー MasKoaTSMasKoaTS
提出日時 2023-09-29 10:19:44
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 340 ms / 2,000 ms
コード長 608 bytes
コンパイル時間 151 ms
コンパイル使用メモリ 82,460 KB
実行使用メモリ 148,820 KB
最終ジャッジ日時 2024-04-12 20:50:34
合計ジャッジ時間 3,001 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 242 ms
132,352 KB
testcase_01 AC 37 ms
52,600 KB
testcase_02 AC 41 ms
58,732 KB
testcase_03 AC 339 ms
148,736 KB
testcase_04 AC 330 ms
148,288 KB
testcase_05 AC 340 ms
148,820 KB
testcase_06 AC 275 ms
147,704 KB
testcase_07 AC 335 ms
148,276 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

query = [int(input()) for _ in [0] * int(input())]

n_max = max(query)
is_prime = [True] * (n_max + 1)
is_prime[0] = is_prime[1] = False
for i in range(2, int(n_max ** 0.5 + 2)):
    if not(is_prime[i]):
        continue
    for j in range(i * i, n_max + 1, i):
        is_prime[j] = False

dp = [0] * (n_max + 1)
ans = [''] * (n_max + 1)
for n in range(2, n_max + 1):
    dp[n] = dp[n - 1]
    if(is_prime[n]):
        dp[n] += 1
        ans[n] = 'P'
        continue
    ans[n] = 'K' if(((n - 2) - dp[n] + dp[n >> 1]) & 1) else 'P'

for n in query:
    print(ans[n])
0