結果
| 問題 |
No.577 Prime Powerful Numbers
|
| コンテスト | |
| ユーザー |
maspy
|
| 提出日時 | 2020-03-25 22:44:55 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,207 bytes |
| コンパイル時間 | 383 ms |
| コンパイル使用メモリ | 12,160 KB |
| 実行使用メモリ | 10,624 KB |
| 最終ジャッジ日時 | 2025-01-02 00:12:49 |
| 合計ジャッジ時間 | 2,719 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 9 WA * 1 |
ソースコード
#!/usr/bin/ python3.8
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def MillerRabinTest(n, maxiter=20):
import random
if n == 1:
return False
elif n == 2:
return True
if not n & 1:
return False
d = n - 1
while not (d & 1):
d >>= 1
for _ in range(maxiter):
a = random.randint(1, n - 1)
t = d
x = pow(a, t, n)
while (t != n - 1) and (x != 1) and (x != n - 1):
x = x * x % n
t <<= 1
if (x != n - 1) and not (t & 1):
return False
return True
def is_pp(N):
if N <= 1:
return False
for n in [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43]:
m = int(N ** (1 / n) + .5)
if m ** n == N:
return is_pp(m)
return MillerRabinTest(N)
def solve(N):
if N == 2:
return False
if N % 2 == 0:
return True
for n in range(64):
x = 1 << n
if x >= N:
return False
if is_pp(N - x):
return True
Q, *N = map(int, read().split())
print('\n'.join('Yes' if solve(n) else 'No' for n in N))
maspy