結果
問題 | No.308 素数は通れません |
ユーザー | chocorusk |
提出日時 | 2019-03-31 10:31:44 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 49 ms / 1,000 ms |
コード長 | 1,374 bytes |
コンパイル時間 | 279 ms |
コンパイル使用メモリ | 82,408 KB |
実行使用メモリ | 56,576 KB |
最終ジャッジ日時 | 2024-11-21 06:27:01 |
合計ジャッジ時間 | 7,104 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 42 ms
55,844 KB |
testcase_01 | AC | 42 ms
55,092 KB |
testcase_02 | AC | 43 ms
56,064 KB |
testcase_03 | AC | 44 ms
56,156 KB |
testcase_04 | AC | 42 ms
55,092 KB |
testcase_05 | AC | 42 ms
55,432 KB |
testcase_06 | AC | 43 ms
54,680 KB |
testcase_07 | AC | 42 ms
54,900 KB |
testcase_08 | AC | 41 ms
54,552 KB |
testcase_09 | AC | 41 ms
54,824 KB |
testcase_10 | AC | 47 ms
55,608 KB |
testcase_11 | AC | 41 ms
56,092 KB |
testcase_12 | AC | 41 ms
54,424 KB |
testcase_13 | AC | 41 ms
55,984 KB |
testcase_14 | AC | 43 ms
56,020 KB |
testcase_15 | AC | 41 ms
55,984 KB |
testcase_16 | AC | 42 ms
55,020 KB |
testcase_17 | AC | 43 ms
55,464 KB |
testcase_18 | AC | 43 ms
54,424 KB |
testcase_19 | AC | 42 ms
54,756 KB |
testcase_20 | AC | 41 ms
54,640 KB |
testcase_21 | AC | 42 ms
54,784 KB |
testcase_22 | AC | 42 ms
54,980 KB |
testcase_23 | AC | 41 ms
54,552 KB |
testcase_24 | AC | 41 ms
55,292 KB |
testcase_25 | AC | 42 ms
54,952 KB |
testcase_26 | AC | 43 ms
55,068 KB |
testcase_27 | AC | 43 ms
54,768 KB |
testcase_28 | AC | 42 ms
55,000 KB |
testcase_29 | AC | 44 ms
55,024 KB |
testcase_30 | AC | 43 ms
55,256 KB |
testcase_31 | AC | 42 ms
55,132 KB |
testcase_32 | AC | 43 ms
55,396 KB |
testcase_33 | AC | 44 ms
54,552 KB |
testcase_34 | AC | 41 ms
54,452 KB |
testcase_35 | AC | 43 ms
55,700 KB |
testcase_36 | AC | 42 ms
55,264 KB |
testcase_37 | AC | 42 ms
56,308 KB |
testcase_38 | AC | 42 ms
54,772 KB |
testcase_39 | AC | 41 ms
55,420 KB |
testcase_40 | AC | 42 ms
54,272 KB |
testcase_41 | AC | 42 ms
54,308 KB |
testcase_42 | AC | 39 ms
54,892 KB |
testcase_43 | AC | 39 ms
55,432 KB |
testcase_44 | AC | 40 ms
55,356 KB |
testcase_45 | AC | 40 ms
54,136 KB |
testcase_46 | AC | 39 ms
55,460 KB |
testcase_47 | AC | 41 ms
54,876 KB |
testcase_48 | AC | 41 ms
56,324 KB |
testcase_49 | AC | 41 ms
56,396 KB |
testcase_50 | AC | 41 ms
54,740 KB |
testcase_51 | AC | 41 ms
54,260 KB |
testcase_52 | AC | 43 ms
55,344 KB |
testcase_53 | AC | 42 ms
55,240 KB |
testcase_54 | AC | 42 ms
54,484 KB |
testcase_55 | AC | 41 ms
55,656 KB |
testcase_56 | AC | 42 ms
55,056 KB |
testcase_57 | AC | 43 ms
55,736 KB |
testcase_58 | AC | 43 ms
55,916 KB |
testcase_59 | AC | 42 ms
54,376 KB |
testcase_60 | AC | 43 ms
54,312 KB |
testcase_61 | AC | 42 ms
54,656 KB |
testcase_62 | AC | 41 ms
54,896 KB |
testcase_63 | AC | 42 ms
55,328 KB |
testcase_64 | AC | 39 ms
54,312 KB |
testcase_65 | AC | 41 ms
54,568 KB |
testcase_66 | AC | 41 ms
54,724 KB |
testcase_67 | AC | 39 ms
55,000 KB |
testcase_68 | AC | 40 ms
55,660 KB |
testcase_69 | AC | 37 ms
55,832 KB |
testcase_70 | AC | 40 ms
55,356 KB |
testcase_71 | AC | 41 ms
54,712 KB |
testcase_72 | AC | 41 ms
55,032 KB |
testcase_73 | AC | 41 ms
55,564 KB |
testcase_74 | AC | 41 ms
55,568 KB |
testcase_75 | AC | 39 ms
56,088 KB |
testcase_76 | AC | 39 ms
55,244 KB |
testcase_77 | AC | 39 ms
55,692 KB |
testcase_78 | AC | 42 ms
54,756 KB |
testcase_79 | AC | 41 ms
54,908 KB |
testcase_80 | AC | 41 ms
55,864 KB |
testcase_81 | AC | 43 ms
55,572 KB |
testcase_82 | AC | 42 ms
54,912 KB |
testcase_83 | AC | 42 ms
55,328 KB |
testcase_84 | AC | 45 ms
54,744 KB |
testcase_85 | AC | 43 ms
54,712 KB |
testcase_86 | AC | 43 ms
56,104 KB |
testcase_87 | AC | 42 ms
54,836 KB |
testcase_88 | AC | 43 ms
54,620 KB |
testcase_89 | AC | 42 ms
54,620 KB |
testcase_90 | AC | 41 ms
55,588 KB |
testcase_91 | AC | 49 ms
55,124 KB |
testcase_92 | AC | 42 ms
54,452 KB |
testcase_93 | AC | 42 ms
54,840 KB |
testcase_94 | AC | 42 ms
55,708 KB |
testcase_95 | AC | 43 ms
54,968 KB |
testcase_96 | AC | 42 ms
55,596 KB |
testcase_97 | AC | 42 ms
56,576 KB |
testcase_98 | AC | 42 ms
56,376 KB |
testcase_99 | AC | 41 ms
55,592 KB |
testcase_100 | AC | 41 ms
55,520 KB |
testcase_101 | AC | 43 ms
55,840 KB |
testcase_102 | AC | 41 ms
55,984 KB |
testcase_103 | AC | 42 ms
55,076 KB |
testcase_104 | AC | 41 ms
55,984 KB |
testcase_105 | AC | 43 ms
54,892 KB |
testcase_106 | AC | 42 ms
56,032 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(102)] isprime=[False for i in range(102)] for i in range(3, 102, 2): isprime[i]=True isprime[2]=True for i in range(3, 102): if isprime[i]: for j in range(2*i, 102, 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<=100: 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(14)