結果
問題 | No.308 素数は通れません |
ユーザー | chocorusk |
提出日時 | 2019-03-31 10:06:50 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,382 bytes |
コンパイル時間 | 246 ms |
コンパイル使用メモリ | 82,320 KB |
実行使用メモリ | 69,752 KB |
最終ジャッジ日時 | 2024-11-21 06:04:26 |
合計ジャッジ時間 | 8,308 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 48 ms
62,120 KB |
testcase_01 | AC | 48 ms
61,468 KB |
testcase_02 | AC | 49 ms
61,416 KB |
testcase_03 | AC | 48 ms
61,760 KB |
testcase_04 | AC | 48 ms
63,096 KB |
testcase_05 | AC | 48 ms
61,316 KB |
testcase_06 | AC | 48 ms
61,756 KB |
testcase_07 | AC | 49 ms
61,892 KB |
testcase_08 | AC | 47 ms
62,256 KB |
testcase_09 | AC | 49 ms
62,256 KB |
testcase_10 | AC | 48 ms
61,352 KB |
testcase_11 | AC | 49 ms
62,960 KB |
testcase_12 | AC | 47 ms
62,064 KB |
testcase_13 | AC | 48 ms
61,232 KB |
testcase_14 | AC | 49 ms
61,452 KB |
testcase_15 | AC | 48 ms
62,324 KB |
testcase_16 | AC | 48 ms
61,232 KB |
testcase_17 | AC | 48 ms
62,420 KB |
testcase_18 | AC | 49 ms
62,756 KB |
testcase_19 | WA | - |
testcase_20 | AC | 49 ms
63,140 KB |
testcase_21 | AC | 47 ms
62,212 KB |
testcase_22 | AC | 48 ms
63,172 KB |
testcase_23 | AC | 48 ms
61,848 KB |
testcase_24 | AC | 48 ms
61,520 KB |
testcase_25 | AC | 48 ms
62,208 KB |
testcase_26 | WA | - |
testcase_27 | AC | 48 ms
61,856 KB |
testcase_28 | AC | 48 ms
61,796 KB |
testcase_29 | AC | 48 ms
61,928 KB |
testcase_30 | AC | 48 ms
61,648 KB |
testcase_31 | WA | - |
testcase_32 | AC | 49 ms
61,272 KB |
testcase_33 | AC | 47 ms
61,316 KB |
testcase_34 | AC | 47 ms
62,220 KB |
testcase_35 | AC | 48 ms
62,436 KB |
testcase_36 | AC | 51 ms
63,428 KB |
testcase_37 | WA | - |
testcase_38 | AC | 50 ms
62,572 KB |
testcase_39 | AC | 50 ms
62,572 KB |
testcase_40 | WA | - |
testcase_41 | AC | 50 ms
63,644 KB |
testcase_42 | AC | 51 ms
63,844 KB |
testcase_43 | AC | 48 ms
61,320 KB |
testcase_44 | AC | 48 ms
63,160 KB |
testcase_45 | AC | 46 ms
61,616 KB |
testcase_46 | AC | 49 ms
62,572 KB |
testcase_47 | AC | 48 ms
62,040 KB |
testcase_48 | AC | 47 ms
61,504 KB |
testcase_49 | AC | 47 ms
63,144 KB |
testcase_50 | AC | 48 ms
61,380 KB |
testcase_51 | AC | 48 ms
62,476 KB |
testcase_52 | AC | 47 ms
61,928 KB |
testcase_53 | AC | 47 ms
61,644 KB |
testcase_54 | AC | 48 ms
62,752 KB |
testcase_55 | AC | 48 ms
61,968 KB |
testcase_56 | AC | 48 ms
62,308 KB |
testcase_57 | AC | 47 ms
61,288 KB |
testcase_58 | AC | 49 ms
62,604 KB |
testcase_59 | AC | 49 ms
61,692 KB |
testcase_60 | AC | 49 ms
63,028 KB |
testcase_61 | AC | 49 ms
61,524 KB |
testcase_62 | AC | 48 ms
62,804 KB |
testcase_63 | AC | 48 ms
62,184 KB |
testcase_64 | AC | 47 ms
62,080 KB |
testcase_65 | AC | 48 ms
62,872 KB |
testcase_66 | AC | 49 ms
63,048 KB |
testcase_67 | AC | 49 ms
61,520 KB |
testcase_68 | AC | 49 ms
61,792 KB |
testcase_69 | AC | 49 ms
62,544 KB |
testcase_70 | AC | 48 ms
62,300 KB |
testcase_71 | AC | 48 ms
61,620 KB |
testcase_72 | AC | 48 ms
61,432 KB |
testcase_73 | AC | 49 ms
63,264 KB |
testcase_74 | AC | 47 ms
62,672 KB |
testcase_75 | AC | 49 ms
61,356 KB |
testcase_76 | WA | - |
testcase_77 | AC | 53 ms
61,980 KB |
testcase_78 | AC | 47 ms
61,592 KB |
testcase_79 | AC | 48 ms
61,624 KB |
testcase_80 | WA | - |
testcase_81 | WA | - |
testcase_82 | AC | 48 ms
62,468 KB |
testcase_83 | AC | 47 ms
61,568 KB |
testcase_84 | WA | - |
testcase_85 | AC | 48 ms
61,464 KB |
testcase_86 | WA | - |
testcase_87 | WA | - |
testcase_88 | AC | 48 ms
62,476 KB |
testcase_89 | AC | 47 ms
61,588 KB |
testcase_90 | WA | - |
testcase_91 | AC | 47 ms
61,980 KB |
testcase_92 | AC | 47 ms
61,812 KB |
testcase_93 | AC | 48 ms
61,880 KB |
testcase_94 | AC | 48 ms
61,384 KB |
testcase_95 | AC | 48 ms
62,416 KB |
testcase_96 | AC | 48 ms
62,664 KB |
testcase_97 | AC | 48 ms
61,460 KB |
testcase_98 | AC | 47 ms
61,652 KB |
testcase_99 | AC | 48 ms
61,844 KB |
testcase_100 | AC | 49 ms
61,644 KB |
testcase_101 | WA | - |
testcase_102 | AC | 49 ms
61,400 KB |
testcase_103 | AC | 46 ms
61,692 KB |
testcase_104 | AC | 48 ms
61,656 KB |
testcase_105 | AC | 47 ms
62,448 KB |
testcase_106 | AC | 48 ms
62,332 KB |
ソースコード
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)