結果
問題 |
No.577 Prime Powerful Numbers
|
ユーザー |
|
提出日時 | 2022-10-02 14:57:31 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,174 bytes |
コンパイル時間 | 188 ms |
コンパイル使用メモリ | 82,432 KB |
実行使用メモリ | 76,672 KB |
最終ジャッジ日時 | 2024-12-25 03:34:26 |
合計ジャッジ時間 | 2,148 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 9 WA * 1 |
ソースコード
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()))