結果

問題 No.308 素数は通れません
ユーザー chocoruskchocorusk
提出日時 2019-03-31 10:10:53
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,380 bytes
コンパイル時間 687 ms
コンパイル使用メモリ 82,584 KB
実行使用メモリ 68,824 KB
最終ジャッジ日時 2024-05-01 04:55:53
合計ジャッジ時間 7,457 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
62,672 KB
testcase_01 AC 45 ms
61,952 KB
testcase_02 AC 43 ms
61,492 KB
testcase_03 AC 43 ms
63,204 KB
testcase_04 AC 44 ms
62,756 KB
testcase_05 AC 43 ms
61,780 KB
testcase_06 AC 43 ms
62,784 KB
testcase_07 AC 42 ms
62,452 KB
testcase_08 AC 42 ms
62,152 KB
testcase_09 AC 40 ms
62,128 KB
testcase_10 AC 41 ms
61,520 KB
testcase_11 AC 43 ms
61,884 KB
testcase_12 AC 43 ms
62,736 KB
testcase_13 AC 47 ms
62,452 KB
testcase_14 AC 46 ms
61,356 KB
testcase_15 AC 41 ms
61,992 KB
testcase_16 AC 42 ms
62,868 KB
testcase_17 AC 42 ms
63,164 KB
testcase_18 AC 42 ms
62,512 KB
testcase_19 AC 42 ms
62,520 KB
testcase_20 AC 43 ms
61,712 KB
testcase_21 AC 42 ms
63,120 KB
testcase_22 AC 43 ms
62,396 KB
testcase_23 AC 43 ms
63,128 KB
testcase_24 AC 43 ms
62,112 KB
testcase_25 AC 46 ms
61,504 KB
testcase_26 AC 42 ms
62,856 KB
testcase_27 AC 43 ms
61,176 KB
testcase_28 AC 42 ms
61,164 KB
testcase_29 AC 43 ms
62,904 KB
testcase_30 AC 42 ms
62,996 KB
testcase_31 AC 42 ms
61,888 KB
testcase_32 AC 47 ms
61,912 KB
testcase_33 AC 44 ms
62,108 KB
testcase_34 AC 43 ms
62,428 KB
testcase_35 AC 42 ms
61,380 KB
testcase_36 AC 44 ms
64,368 KB
testcase_37 AC 44 ms
63,352 KB
testcase_38 AC 44 ms
63,372 KB
testcase_39 AC 43 ms
64,124 KB
testcase_40 AC 44 ms
63,440 KB
testcase_41 AC 46 ms
64,644 KB
testcase_42 AC 54 ms
68,824 KB
testcase_43 AC 42 ms
62,764 KB
testcase_44 AC 41 ms
62,388 KB
testcase_45 AC 41 ms
62,104 KB
testcase_46 AC 44 ms
61,656 KB
testcase_47 AC 44 ms
62,200 KB
testcase_48 AC 43 ms
62,744 KB
testcase_49 AC 44 ms
61,604 KB
testcase_50 AC 41 ms
62,412 KB
testcase_51 AC 45 ms
63,052 KB
testcase_52 AC 43 ms
61,440 KB
testcase_53 AC 42 ms
62,800 KB
testcase_54 AC 41 ms
61,520 KB
testcase_55 AC 41 ms
61,888 KB
testcase_56 AC 41 ms
62,300 KB
testcase_57 AC 41 ms
61,616 KB
testcase_58 AC 42 ms
62,368 KB
testcase_59 AC 44 ms
61,664 KB
testcase_60 AC 44 ms
63,088 KB
testcase_61 AC 41 ms
61,408 KB
testcase_62 AC 42 ms
62,228 KB
testcase_63 AC 41 ms
61,920 KB
testcase_64 AC 42 ms
61,640 KB
testcase_65 AC 42 ms
63,144 KB
testcase_66 AC 45 ms
61,912 KB
testcase_67 AC 42 ms
62,580 KB
testcase_68 AC 42 ms
62,372 KB
testcase_69 AC 41 ms
62,460 KB
testcase_70 AC 43 ms
62,016 KB
testcase_71 AC 47 ms
61,556 KB
testcase_72 AC 45 ms
61,828 KB
testcase_73 AC 41 ms
61,824 KB
testcase_74 AC 42 ms
62,408 KB
testcase_75 AC 42 ms
62,256 KB
testcase_76 WA -
testcase_77 AC 43 ms
61,680 KB
testcase_78 AC 42 ms
61,460 KB
testcase_79 AC 42 ms
61,556 KB
testcase_80 WA -
testcase_81 WA -
testcase_82 AC 43 ms
62,076 KB
testcase_83 AC 43 ms
61,748 KB
testcase_84 WA -
testcase_85 AC 44 ms
61,700 KB
testcase_86 WA -
testcase_87 WA -
testcase_88 AC 42 ms
61,364 KB
testcase_89 AC 43 ms
61,644 KB
testcase_90 WA -
testcase_91 AC 44 ms
61,780 KB
testcase_92 AC 42 ms
61,856 KB
testcase_93 AC 51 ms
61,796 KB
testcase_94 AC 48 ms
62,688 KB
testcase_95 AC 42 ms
62,484 KB
testcase_96 AC 42 ms
62,492 KB
testcase_97 AC 46 ms
62,200 KB
testcase_98 AC 43 ms
61,272 KB
testcase_99 AC 44 ms
61,556 KB
testcase_100 AC 43 ms
63,384 KB
testcase_101 WA -
testcase_102 AC 42 ms
62,732 KB
testcase_103 AC 41 ms
62,080 KB
testcase_104 AC 42 ms
62,088 KB
testcase_105 AC 42 ms
62,604 KB
testcase_106 AC 43 ms
61,296 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import random
import sys
def is_prime(n):
    if n == 2: return True
    if n == 1 or n & 1 == 0: return False

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

    for k in range(10):
        a = random.randint(1, n - 1)
        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

n=int(input())
used=[False for i in range(2002)]
isprime=[False for i in range(2002)]
for i in range(3, 2002, 2):
    isprime[i]=True
isprime[2]=True
for i in range(3, 2002):
    if isprime[i]:
        for j in range(2*i, 2002, i):
            isprime[j]=False

def dfs(x, w):
    used[x]=True
    if x%w!=1 and (not used[x-1]) and (not isprime[x-1]):
        dfs(x-1, w)
    if x%w!=0 and x+1<=n and (not used[x+1]) and (not isprime[x+1]):
        dfs(x+1, w)
    if x>w and (not used[x-w]) and (not isprime[x-w]):
        dfs(x-w, w)
    if x+w<=n and (not used[x+w]) and (not isprime[x+w]):
        dfs(x+w, w)
def solve(w):
    for i in range(1, n+1):
        used[i]=False
    dfs(1, w)
    return used[n]

if n<=2000:
    for i in range(3, n):
        if solve(i):
            print(i)
            sys.exit()
else:
    if n%8!=1:
        print(8)
    elif not is_prime(n-8):
        print(8)
    else:
        print(13)
0