結果

問題 No.36 素数が嫌い!
ユーザー Masahiro HMasahiro H
提出日時 2016-02-29 21:51:44
言語 Python2
(2.7.18)
結果
RE  
実行時間 -
コード長 506 bytes
コンパイル時間 610 ms
コンパイル使用メモリ 7,060 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2023-10-24 19:14:09
合計ジャッジ時間 1,354 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
6,400 KB
testcase_01 RE -
testcase_02 AC 12 ms
6,400 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 RE -
testcase_07 RE -
testcase_08 AC 10 ms
6,400 KB
testcase_09 AC 10 ms
6,400 KB
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 AC 10 ms
6,400 KB
testcase_16 RE -
testcase_17 WA -
testcase_18 AC 9 ms
6,400 KB
testcase_19 AC 10 ms
6,400 KB
testcase_20 RE -
testcase_21 AC 10 ms
6,400 KB
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

def is_prime(q,k=50):
    q = abs(q)

    if q == 2: return True
    if q < 2 or q&1 == 0: return False

    d = (q-1)>>1
    while d&1 == 0:
        d >>= 1

    for i in xrange(k):
        a = random.randint(1,q-1)
        t = d
        y = pow(a,t,q)

        while t != q-1 and y != 1 and y != q-1: 
            y = pow(y,2,q)
            t <<= 1
        if y != q-1 and t&1 == 0:
            return False
    return True

d = int(raw_input())

if is_prime(d):
    print("NO")
else:
    print("YES")

0