結果
問題 | No.3030 ミラー・ラビン素数判定法のテスト |
ユーザー | zimpha |
提出日時 | 2017-12-07 22:27:33 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 501 ms / 9,973 ms |
コード長 | 504 bytes |
コンパイル時間 | 225 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 76,928 KB |
最終ジャッジ日時 | 2024-04-28 09:14:07 |
合計ジャッジ時間 | 2,860 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 46 ms
52,096 KB |
testcase_01 | AC | 42 ms
51,712 KB |
testcase_02 | AC | 42 ms
51,840 KB |
testcase_03 | AC | 42 ms
52,096 KB |
testcase_04 | AC | 344 ms
76,928 KB |
testcase_05 | AC | 328 ms
76,416 KB |
testcase_06 | AC | 207 ms
76,672 KB |
testcase_07 | AC | 206 ms
76,800 KB |
testcase_08 | AC | 203 ms
76,544 KB |
testcase_09 | AC | 501 ms
76,672 KB |
ソースコード
def is_prime(n): if n <= 1: return False if n <= 3: return True if n % 2 == 0: return False u = [2, 3, 5, 7, 325, 9375, 28178, 450775, 9780504, 1795265022] e, c = n - 1, 0 while e % 2 == 0: e >>= 1 c += 1 for p in u: if n <= p: return True a = pow(p, e, n) if a == 1: continue j = 1 while a != n - 1: if j == c: return False a = a * a % n j += 1 return True for i in range(int(input())): x = int(input()) print(x, int(is_prime(x)))