結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
62,424 KB
testcase_01 AC 44 ms
63,112 KB
testcase_02 AC 45 ms
61,824 KB
testcase_03 AC 46 ms
61,164 KB
testcase_04 AC 43 ms
62,708 KB
testcase_05 AC 43 ms
61,532 KB
testcase_06 AC 46 ms
61,588 KB
testcase_07 AC 45 ms
63,068 KB
testcase_08 AC 43 ms
62,320 KB
testcase_09 AC 42 ms
62,528 KB
testcase_10 AC 43 ms
61,792 KB
testcase_11 AC 44 ms
61,544 KB
testcase_12 AC 44 ms
62,468 KB
testcase_13 AC 41 ms
62,608 KB
testcase_14 AC 41 ms
62,608 KB
testcase_15 AC 41 ms
62,524 KB
testcase_16 AC 41 ms
62,408 KB
testcase_17 AC 41 ms
61,892 KB
testcase_18 AC 41 ms
62,212 KB
testcase_19 WA -
testcase_20 AC 44 ms
61,884 KB
testcase_21 AC 44 ms
61,692 KB
testcase_22 AC 42 ms
62,100 KB
testcase_23 AC 40 ms
62,176 KB
testcase_24 AC 42 ms
62,860 KB
testcase_25 AC 42 ms
62,784 KB
testcase_26 WA -
testcase_27 AC 41 ms
61,764 KB
testcase_28 AC 41 ms
63,120 KB
testcase_29 AC 40 ms
62,152 KB
testcase_30 AC 42 ms
62,340 KB
testcase_31 WA -
testcase_32 AC 41 ms
63,384 KB
testcase_33 AC 41 ms
61,904 KB
testcase_34 AC 41 ms
61,652 KB
testcase_35 AC 42 ms
61,724 KB
testcase_36 AC 42 ms
62,812 KB
testcase_37 WA -
testcase_38 AC 44 ms
64,136 KB
testcase_39 AC 43 ms
62,488 KB
testcase_40 WA -
testcase_41 AC 48 ms
64,312 KB
testcase_42 AC 48 ms
63,908 KB
testcase_43 AC 45 ms
62,468 KB
testcase_44 AC 42 ms
61,840 KB
testcase_45 AC 40 ms
62,328 KB
testcase_46 AC 41 ms
61,292 KB
testcase_47 AC 44 ms
61,980 KB
testcase_48 AC 41 ms
62,144 KB
testcase_49 AC 42 ms
61,792 KB
testcase_50 AC 42 ms
61,640 KB
testcase_51 AC 42 ms
61,952 KB
testcase_52 AC 44 ms
61,460 KB
testcase_53 AC 41 ms
61,644 KB
testcase_54 AC 42 ms
61,464 KB
testcase_55 AC 44 ms
61,604 KB
testcase_56 AC 43 ms
61,436 KB
testcase_57 AC 43 ms
61,480 KB
testcase_58 AC 42 ms
62,300 KB
testcase_59 AC 43 ms
61,336 KB
testcase_60 AC 41 ms
62,556 KB
testcase_61 AC 40 ms
61,720 KB
testcase_62 AC 41 ms
61,460 KB
testcase_63 AC 41 ms
62,208 KB
testcase_64 AC 42 ms
61,976 KB
testcase_65 AC 44 ms
61,360 KB
testcase_66 AC 42 ms
62,176 KB
testcase_67 AC 42 ms
61,452 KB
testcase_68 AC 42 ms
61,648 KB
testcase_69 AC 43 ms
62,988 KB
testcase_70 AC 45 ms
61,444 KB
testcase_71 AC 46 ms
61,568 KB
testcase_72 AC 45 ms
63,240 KB
testcase_73 AC 45 ms
61,584 KB
testcase_74 AC 44 ms
61,424 KB
testcase_75 AC 44 ms
61,320 KB
testcase_76 WA -
testcase_77 AC 41 ms
62,136 KB
testcase_78 AC 43 ms
62,624 KB
testcase_79 AC 42 ms
61,576 KB
testcase_80 WA -
testcase_81 WA -
testcase_82 AC 44 ms
61,452 KB
testcase_83 AC 41 ms
61,340 KB
testcase_84 WA -
testcase_85 AC 45 ms
61,564 KB
testcase_86 WA -
testcase_87 WA -
testcase_88 AC 46 ms
61,824 KB
testcase_89 AC 57 ms
62,132 KB
testcase_90 WA -
testcase_91 AC 46 ms
62,540 KB
testcase_92 AC 46 ms
62,332 KB
testcase_93 AC 44 ms
63,032 KB
testcase_94 AC 43 ms
62,492 KB
testcase_95 AC 43 ms
61,544 KB
testcase_96 AC 46 ms
61,752 KB
testcase_97 AC 43 ms
62,188 KB
testcase_98 AC 43 ms
62,600 KB
testcase_99 AC 46 ms
61,412 KB
testcase_100 AC 45 ms
61,580 KB
testcase_101 WA -
testcase_102 AC 44 ms
61,228 KB
testcase_103 AC 45 ms
62,564 KB
testcase_104 AC 43 ms
62,208 KB
testcase_105 AC 43 ms
62,080 KB
testcase_106 AC 44 ms
62,732 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!=w-1 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