結果

問題 No.577 Prime Powerful Numbers
ユーザー 👑 rin204rin204
提出日時 2022-10-02 14:57:31
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,174 bytes
コンパイル時間 574 ms
コンパイル使用メモリ 86,640 KB
実行使用メモリ 77,768 KB
最終ジャッジ日時 2023-08-26 09:18:54
合計ジャッジ時間 2,884 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
76,060 KB
testcase_01 AC 120 ms
77,124 KB
testcase_02 WA -
testcase_03 AC 130 ms
77,768 KB
testcase_04 AC 83 ms
76,412 KB
testcase_05 AC 279 ms
77,612 KB
testcase_06 AC 100 ms
77,188 KB
testcase_07 AC 288 ms
77,600 KB
testcase_08 AC 126 ms
77,576 KB
testcase_09 AC 127 ms
77,548 KB
testcase_10 AC 63 ms
71,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def isprime(n):
    if n <= 1:
        return False
    elif n == 2:
        return True
    elif n % 2 == 0:
        return False
    
    A = [2, 325, 9375, 28178, 450775, 9780504, 1795265022]
    s = 0
    d = n - 1
    while d % 2 == 0:
        s += 1
        d >>= 1
    
    for a in A:
        if a % n == 0:
            return True
        x = pow(a, d, n)
        if x != 1:
            for t in range(s):
                if x == n - 1:
                    break
                x = x * x % n
            else:
                return False
    return True
        
def invc(x, c):
    i = int(x ** (1 / c))
    while i ** c < x:
        i += 1
    while i ** c > x:
        i -= 1
    return i

def ok(x):
    if isprime(x):
        return True
    
    c = 2
    while 1:
        i = invc(x, c)
        if i ** c == x:
            return True
        if i <= 2:
            break
        c += 1



    return False


def solve(x):
    if not x & 1:
        print("Yes")
        return

    b = 2
    while b < x:
        if ok(x - b):
            print("Yes")
            return
        b *= 2
    print("No")

for _ in range(int(input())):
    solve(int(input()))
0