結果
| 問題 |
No.8030 ミラー・ラビン素数判定法のテスト
|
| ユーザー |
|
| 提出日時 | 2022-08-26 12:49:57 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,230 bytes |
| コンパイル時間 | 114 ms |
| コンパイル使用メモリ | 12,672 KB |
| 実行使用メモリ | 10,752 KB |
| 最終ジャッジ日時 | 2024-10-13 14:45:08 |
| 合計ジャッジ時間 | 5,013 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 3 WA * 7 |
ソースコード
def is_prime(n):
if n == 2:
return 1
if n == 1 or n % 2 == 0:
return 0
m = n - 1
lsb = m & -m
s = lsb.bit_length() - 1
d = m // lsb
if n < 341531:
bases = [9345883071009581737]
elif n < 1050535501:
bases = [336781006125, 9639812373923155]
elif n < 350269456337:
bases = [4230279247111683200, 14694767155120705706, 16641139526367750375]
elif n < 55245642489451:
bases = [2, 141889084524735, 1199124725622454117, 11096072698276303650]
elif n < 7999252175582851:
bases = [2, 4130806001517, 149795463772692060, 186635894390467037, 3967304179347715805]
elif n < 585226005592931977:
bases = [2, 123635709730000, 9233062284813009, 43835965440333360, 761179012939631437, 1263739024124850375]
else:
bases = [2, 325, 9375, 28178, 450775, 9780504, 1795265022]
for a in bases:
if n <= a:
continue
x = pow(a, d, n)
r = 0
if x == 1:
continue
while x != m:
x = pow(x, 2, n)
r += 1
if x == 1 or r == s:
return 0
return 1
for _ in range(int(input())):
x = int(input())
print(x, is_prime(x))