結果
問題 |
No.8030 ミラー・ラビン素数判定法のテスト
|
ユーザー |
|
提出日時 | 2022-08-26 12:44:03 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,271 bytes |
コンパイル時間 | 181 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 11,264 KB |
最終ジャッジ日時 | 2024-10-13 14:39:44 |
合計ジャッジ時間 | 5,630 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 9 WA * 1 |
ソースコード
from random import randrange from math import gcd 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] if n < 1050535501: bases = [336781006125, 9639812373923155] if n < 350269456337: bases = [4230279247111683200, 14694767155120705706, 16641139526367750375] if n < 55245642489451: bases = [2, 141889084524735, 1199124725622454117, 11096072698276303650] if n < 7999252175582851: bases = [2, 4130806001517, 149795463772692060, 186635894390467037, 3967304179347715805] if n < 585226005592931977: bases = [2, 123635709730000, 9233062284813009, 43835965440333360, 761179012939631437, 1263739024124850375] else: bases = [2, 325, 9375, 28178, 450775, 9780504, 1795265022] for a in bases: if a == n: 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 i in range(int(input())): x = int(input()) print(x, is_prime(x))