結果

問題 No.3030 ミラー・ラビン素数判定法のテスト
ユーザー shop_oneshop_one
提出日時 2020-05-30 00:32:07
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 878 bytes
コンパイル時間 357 ms
コンパイル使用メモリ 10,968 KB
実行使用メモリ 8,932 KB
最終ジャッジ日時 2023-08-11 22:50:53
合計ジャッジ時間 12,098 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 20 ms
8,932 KB
testcase_01 AC 18 ms
8,828 KB
testcase_02 AC 20 ms
8,792 KB
testcase_03 AC 19 ms
8,820 KB
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import random
import math


def judge_miller(val):
    if(val == 1):
        return False
    if(val == 2):
        return True
    if(val % 2 == 0):
        return False
    d = val - 1
    while(d & 1 == 0):
        d >>= 1
    for k in range(100):
        a = random.randint(2, val - 1)
        may_prime = False
        x = pow(a, d, val)
        if(x == 1):
            may_prime = True
        while(not may_prime):
            if(x == val - 1):
                may_prime = True
            d <<= 1
            x = (x * a * a) % val
            if(d == val-1):
                break
        if(not may_prime):
            return False
    return True


if __name__ == "__main__":
    x = int(input())
    for i in range(x):
        v = int(input())
        res = judge_miller(v)
        if(res):
            print(str(v)+" 1")
        else:
            print(str(v)+" 0")
0