結果
| 問題 |
No.8030 ミラー・ラビン素数判定法のテスト
|
| ユーザー |
kemuniku
|
| 提出日時 | 2022-09-24 04:26:50 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 648 bytes |
| コンパイル時間 | 271 ms |
| コンパイル使用メモリ | 82,176 KB |
| 実行使用メモリ | 77,184 KB |
| 最終ジャッジ日時 | 2024-12-22 05:48:30 |
| 合計ジャッジ時間 | 2,579 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 5 WA * 5 |
ソースコード
def isprime(N):
bases = [2,325,9375,28178,450775,9780504,1795265022]
if N < 2:
return False
if N == 2:
return True
if N%2 == 0:
return False
s,t = (N & -N).bit_length()-1,N//(N & -N)
for b in bases:
if b % N == 0:
continue
t = pow(b,N-1,N)
if t == 1 or t == N-1:
continue
for _ in range(s-1):
t = pow(t,2,N)
if t == N-1:
break
else:
return False
return True
N = int(input())
for i in range(N):
X =int(input())
if isprime(X):
print(X,1)
else:
print(X,0)
kemuniku