結果

問題 No.2724 Coprime Game 1
ユーザー hato336hato336
提出日時 2024-04-12 22:00:14
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,572 ms / 2,000 ms
コード長 1,456 bytes
コンパイル時間 383 ms
コンパイル使用メモリ 82,004 KB
実行使用メモリ 234,804 KB
最終ジャッジ日時 2024-04-12 22:00:29
合計ジャッジ時間 14,222 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,416 ms
234,732 KB
testcase_01 AC 1,437 ms
234,208 KB
testcase_02 AC 1,429 ms
233,892 KB
testcase_03 AC 1,471 ms
234,072 KB
testcase_04 AC 1,571 ms
233,888 KB
testcase_05 AC 1,556 ms
234,164 KB
testcase_06 AC 1,500 ms
234,804 KB
testcase_07 AC 1,572 ms
234,092 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import collections,sys,math,functools,operator,itertools,bisect,heapq,decimal,string,time,random
#sys.setrecursionlimit(10**9)
#sys.set_int_max_str_digits(0)
input = sys.stdin.readline
t = int(input())
#alist = list(map(int,input().split()))
#alist = []
#s = input()
#n,m = map(int,input().split())
#for i in range(n):
def MillerRabin_64bit(x):
    if x <= 1:
        return False
    if x == 2:
        return True
    if x % 2 == 0:
        return False
    if x < 1 << 30:
        test = [2, 7, 61]
    else:
        test = [2,325,9375,28178,450775,9780504,1795265022]
    s = 0
    d = x - 1
    while d & 1 == 0:
        s += 1
        d >>= 1
    for i in test:
        if x <= i:
            return True
        y = pow(i,d,x)
        if y == 1 or y == x - 1:
            continue
        c = 0
        for j in range(s-1):
            y = y * y % x
            if y == x - 1:
                c = 1
                break
        if not c:
            return False
    return True
#    alist.append(list(map(int,input().split())))
check = [0 for i in range(3*10**6+10)]

for i in range(2,3*10**6+10):
    check[i] = 1 if MillerRabin_64bit(i) == True else 0

check = list(itertools.accumulate(check))

for _ in range(t):
    n = int(input())
    if n == 4:
        print('K')
        continue
    if MillerRabin_64bit(n):
        print('P')
        continue
    cnt = n - 1
    cnt -= check[n] - check[n // 2]
    #print(n,cnt)

    print('KP'[cnt%2])
0