結果

問題 No.308 素数は通れません
ユーザー Hiroyasu Yoshino
提出日時 2022-04-23 00:27:58
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
RE  
実行時間 -
コード長 421 bytes
コンパイル時間 253 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 11,392 KB
最終ジャッジ日時 2024-06-24 06:04:13
合計ジャッジ時間 6,442 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other RE * 107
権限があれば一括ダウンロードができます

ソースコード

diff #

from random import randint
n = input()

m = {3: [4], 5: [6], 7: [8,9,10,15,16,22], 11: [12], 13: [14], 19: [20,21], 23: [24,25]}

def fermat(k):
    for t in xrange(1000):
        a = randint(2, k-1)
        if pow(a, k-1, k)!=1:
            return False
    return True

for w in m:
    if n in m[w]:
        print(w)
        exit(0)

if (n%8!=1 and not fermat(n-1)) or not fermat(n-8):
    print(8)
else:
    print(14)
0