結果

問題 No.3030 ミラー・ラビン素数判定法のテスト
ユーザー shotoyooshotoyoo
提出日時 2021-06-17 23:51:59
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 481 ms / 9,973 ms
コード長 883 bytes
コンパイル時間 144 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 77,824 KB
最終ジャッジ日時 2024-04-28 09:43:42
合計ジャッジ時間 2,385 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
54,144 KB
testcase_01 AC 40 ms
53,632 KB
testcase_02 AC 39 ms
54,272 KB
testcase_03 AC 38 ms
54,272 KB
testcase_04 AC 313 ms
77,696 KB
testcase_05 AC 290 ms
77,824 KB
testcase_06 AC 152 ms
77,440 KB
testcase_07 AC 150 ms
77,312 KB
testcase_08 AC 152 ms
77,696 KB
testcase_09 AC 481 ms
77,440 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda : sys.stdin.readline().rstrip()

sys.setrecursionlimit(2*10**5+10)
write = lambda x: sys.stdout.write(x+"\n")
debug = lambda x: sys.stderr.write(x+"\n")
writef = lambda x: print("{:.12f}".format(x))

from math import gcd
import random
def is_prime(n):
    """miller_rabinによる素数判定
    ※ 1は素数と扱う
    """
    l = [2,3,5,7,11,13,17,19,23,29,31,37]
    if n==1 or n in l:
        return True
    d = n-1
    s = 0
    while d%2==0:
        s += 1
        d //= 2
    for a in l:
        v = pow(a,d,n)
        if v==1 or v==n-1:
            continue
        for _ in range(s):
            v = v*v % n
            if v==n-1:
                break
        else:
            return False
    return True

n = int(input())
for i in range(n):
    v = int(input())
    if is_prime(v) and v!=1:
        print(v,1)
    else:
        print(v,0)
0