結果

問題 No.36 素数が嫌い!
ユーザー convexineqconvexineq
提出日時 2020-11-25 06:39:57
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 763 bytes
コンパイル時間 280 ms
コンパイル使用メモリ 86,932 KB
実行使用メモリ 71,400 KB
最終ジャッジ日時 2023-10-01 01:39:40
合計ジャッジ時間 3,967 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
71,396 KB
testcase_01 AC 69 ms
70,900 KB
testcase_02 AC 70 ms
71,152 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 72 ms
71,368 KB
testcase_08 AC 69 ms
71,324 KB
testcase_09 AC 69 ms
71,044 KB
testcase_10 AC 71 ms
71,212 KB
testcase_11 AC 69 ms
71,184 KB
testcase_12 AC 68 ms
71,192 KB
testcase_13 WA -
testcase_14 AC 68 ms
71,168 KB
testcase_15 AC 72 ms
71,096 KB
testcase_16 AC 70 ms
71,208 KB
testcase_17 WA -
testcase_18 AC 70 ms
71,052 KB
testcase_19 AC 71 ms
71,344 KB
testcase_20 AC 70 ms
71,372 KB
testcase_21 AC 70 ms
71,128 KB
testcase_22 AC 72 ms
71,060 KB
testcase_23 AC 70 ms
71,400 KB
testcase_24 AC 72 ms
71,200 KB
testcase_25 AC 72 ms
71,128 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

def isprime_Miller(n):
    if n==2: return True
    if n==1 or n&1==0: return False
    
    if n < (1<<32): witness = [2,7,61]
    else: witness = [2, 325, 9375, 28178, 450775, 9780504, 1795265022] # n < (1<<64) でOK 
    #elif n < (1<<61): witness = [2,3,5,7,11,13,17,19,23]
    #if n in witness: return True
    
    d = n-1
    while d&1==0: d >>= 1
    for a in witness:
        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 t&1 == 0: return False
    return True

# coding: utf-8
# Your code here!
import sys
readline = sys.stdin.readline
read = sys.stdin.read

#a,b,c = map(int,readline().split())
n = int(input())
print("NO" if isprime_Miller(n) else "YES")
0