結果
| 問題 |
No.8030 ミラー・ラビン素数判定法のテスト
|
| ユーザー |
るこーそー
|
| 提出日時 | 2024-09-09 22:08:16 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 953 ms / 9,973 ms |
| コード長 | 429 bytes |
| コンパイル時間 | 361 ms |
| コンパイル使用メモリ | 82,432 KB |
| 実行使用メモリ | 78,540 KB |
| 最終ジャッジ日時 | 2024-09-09 22:08:21 |
| 合計ジャッジ時間 | 4,859 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 10 |
ソースコード
import random
def MillerRabin(n,k=20):
if n==2:return True
if n<2 or n%2==0:return False
s,d=0,n-1
while d&1==0:
s+=1
d>>=1
for _ in range(k):
a=random.randint(1,n-1)
x=pow(a,d,n)
if x!=1 and x!=n-1:
for __ in range(s):
x=pow(x,2,n)
if x==n-1:break
else:return False
return True
n=int(input())
for _ in range(n):
x=int(input())
print(x,1 if MillerRabin(x) else 0)
るこーそー