結果
問題 | No.3030 ミラー・ラビン素数判定法のテスト |
ユーザー | GrayCoder |
提出日時 | 2018-11-11 10:11:32 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 7,765 ms / 9,973 ms |
コード長 | 656 bytes |
コンパイル時間 | 480 ms |
コンパイル使用メモリ | 10,808 KB |
実行使用メモリ | 9,892 KB |
最終ジャッジ日時 | 2023-08-10 16:05:12 |
合計ジャッジ時間 | 17,310 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge13 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 17 ms
8,796 KB |
testcase_01 | AC | 17 ms
8,728 KB |
testcase_02 | AC | 20 ms
8,740 KB |
testcase_03 | AC | 18 ms
8,716 KB |
testcase_04 | AC | 3,817 ms
9,824 KB |
testcase_05 | AC | 3,441 ms
9,708 KB |
testcase_06 | AC | 298 ms
9,852 KB |
testcase_07 | AC | 291 ms
9,744 KB |
testcase_08 | AC | 293 ms
9,864 KB |
testcase_09 | AC | 7,765 ms
9,892 KB |
ソースコード
import random from sys import stdin, stdout def main(): N = int(input()) X = map(int, stdin.read().splitlines()) for i in X: stdout.write(str(i) + ' ' + is_prime(i) + '\n') 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 k in range(40): 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' input = lambda: stdin.readline() main()