結果

問題 No.2724 Coprime Game 1
ユーザー Ekiben542Ekiben542
提出日時 2024-04-12 22:14:30
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 582 bytes
コンパイル時間 194 ms
コンパイル使用メモリ 82,100 KB
実行使用メモリ 113,400 KB
最終ジャッジ日時 2024-04-12 22:14:38
合計ジャッジ時間 6,833 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import gcd

def soln(N):
    vis = [False] * (N + 1)
    vis[1] = True  
    
    def find_coprime(x):
        for i in range(2, N + 1):
            if vis[i] or gcd(x, i) == 1:
                continue
            return i
        return -1
    
    x = 2
    while True:
        y = find_coprime(x)
        if y == -1:
            return "K"
        vis[y] = True
        x = y
        
        y = find_coprime(x)
        if y == -1:
            return "P"
        vis[y] = True
        x = y

T = int(input())
for _ in range(T):
    N = int(input())
    print(soln(N))
0