結果
| 問題 |
No.8030 ミラー・ラビン素数判定法のテスト
|
| ユーザー |
nonamae
|
| 提出日時 | 2022-08-16 15:07:51 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,340 bytes |
| コンパイル時間 | 203 ms |
| コンパイル使用メモリ | 82,404 KB |
| 実行使用メモリ | 67,280 KB |
| 最終ジャッジ日時 | 2024-10-03 06:09:02 |
| 合計ジャッジ時間 | 1,339 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | RE * 10 |
ソースコード
class LCGs:
def __init__(self):
self.state = 14534622846793005
def rand(self):
self.state *= 6364136223846793005
self.state += 1442695040888963407
self.state &= 18446744073709551615
return self.state
def range(self, left, right):
return left + self.rand() % (right - left + 1)
def jacobi(a, n):
t = 0
j = 1
while a != 0:
if a < 0:
a = -a
if (n & 3) == 3:
j = -j
s = (a & -a).bit_length()
a >>= s
if ((n & 7) == 3 or (n & 7) == 5) and (s & 1 == 1):
j = -j
if (a & n & 3) == 3:
j = -j
t = a
a = n,
n = t
a %= n
if a > (n // 2):
a -= n
return j if n == 1 else 0
def solovay_strassen(n):
if n == 0 or n == 1:
return False
if n == 2 or n == 3:
return True
if n & 1 == 0:
return False
rnd = LCGs()
for _ in range(13):
a = rnd.range(2, 100000000)
x = jacobi(a, n)
y = n - 1
if x == 0:
y = 0
elif x != -1:
y = 1
if y == 0 or y != pow(a, (n - 1) // 2, n):
return False
return True
q = int(input())
for _ in range(q):
a = int(input())
print(a, int(solovay_strassen(a)))
nonamae