結果

問題 No.577 Prime Powerful Numbers
ユーザー 👑 rin204rin204
提出日時 2022-10-02 14:59:30
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 287 ms / 2,000 ms
コード長 1,224 bytes
コンパイル時間 374 ms
コンパイル使用メモリ 87,060 KB
実行使用メモリ 77,852 KB
最終ジャッジ日時 2023-08-26 09:20:21
合計ジャッジ時間 2,442 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
76,212 KB
testcase_01 AC 86 ms
77,236 KB
testcase_02 AC 66 ms
71,504 KB
testcase_03 AC 125 ms
77,580 KB
testcase_04 AC 86 ms
76,780 KB
testcase_05 AC 287 ms
77,712 KB
testcase_06 AC 95 ms
77,180 KB
testcase_07 AC 273 ms
77,492 KB
testcase_08 AC 120 ms
77,852 KB
testcase_09 AC 124 ms
77,636 KB
testcase_10 AC 63 ms
71,540 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 <= 2:
            break
        if i ** c == x:
            return True
        c += 1



    return False


def solve(x):
    if x == 2:
        print("No")
        return
    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