結果

問題 No.36 素数が嫌い!
ユーザー Masahiro H
提出日時 2016-02-29 21:51:44
言語 Python2
(2.7.18)
結果
RE  
実行時間 -
コード長 506 bytes
コンパイル時間 238 ms
コンパイル使用メモリ 7,068 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-09-24 12:54:12
合計ジャッジ時間 1,577 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 1 RE * 1
other AC * 6 WA * 3 RE * 17
権限があれば一括ダウンロードができます

ソースコード

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