結果
| 問題 |
No.8030 ミラー・ラビン素数判定法のテスト
|
| ユーザー |
|
| 提出日時 | 2025-08-10 22:41:25 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 5,305 ms / 9,973 ms |
| コード長 | 826 bytes |
| コンパイル時間 | 379 ms |
| コンパイル使用メモリ | 11,904 KB |
| 実行使用メモリ | 10,624 KB |
| 最終ジャッジ日時 | 2025-08-10 22:41:41 |
| 合計ジャッジ時間 | 13,847 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 10 |
ソースコード
import random
import sys
def is_prime(n):
if n == 2:
return 1
if n == 1 or not n % 2:
return 0
d = (n - 1) >> 1
while not d % 2:
d >>= 1
for _ in [0] * 20:
a = random.randint(1, n - 1)
t = d
y = pow(a, t, n)
while t != n - 1 and y != 1 and y != n - 1:
y = (y * y) % n
t <<= 1
if y != n - 1 and not t % 2:
return 0
return 1
def main():
# sys.setrecursionlimit(100000)
input = lambda: sys.stdin.readline()[:-1]
N = int(input())
for _ in [0] * N:
X = int(input())
ans = is_prime(X)
print(X, ans)
if not __debug__:
f = open(sys.argv[1], "r")
sys.stdin = f
# try:
# sys.set_int_max_str_digits(100000)
# except AttributeError:
# pass
main()