結果
問題 | No.308 素数は通れません |
ユーザー | 0w1 |
提出日時 | 2017-04-15 20:52:34 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 98 ms / 1,000 ms |
コード長 | 1,093 bytes |
コンパイル時間 | 259 ms |
コンパイル使用メモリ | 81,584 KB |
実行使用メモリ | 78,796 KB |
最終ジャッジ日時 | 2024-05-05 18:45:14 |
合計ジャッジ時間 | 10,375 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 67 ms
69,688 KB |
testcase_01 | AC | 68 ms
69,060 KB |
testcase_02 | AC | 69 ms
69,544 KB |
testcase_03 | AC | 68 ms
70,556 KB |
testcase_04 | AC | 69 ms
70,780 KB |
testcase_05 | AC | 69 ms
70,872 KB |
testcase_06 | AC | 75 ms
72,464 KB |
testcase_07 | AC | 69 ms
70,124 KB |
testcase_08 | AC | 69 ms
69,344 KB |
testcase_09 | AC | 74 ms
71,604 KB |
testcase_10 | AC | 81 ms
75,144 KB |
testcase_11 | AC | 83 ms
75,028 KB |
testcase_12 | AC | 70 ms
70,752 KB |
testcase_13 | AC | 95 ms
78,696 KB |
testcase_14 | AC | 93 ms
78,640 KB |
testcase_15 | AC | 75 ms
73,884 KB |
testcase_16 | AC | 77 ms
73,284 KB |
testcase_17 | AC | 77 ms
72,664 KB |
testcase_18 | AC | 82 ms
75,300 KB |
testcase_19 | AC | 93 ms
78,644 KB |
testcase_20 | AC | 78 ms
74,848 KB |
testcase_21 | AC | 79 ms
74,392 KB |
testcase_22 | AC | 78 ms
74,228 KB |
testcase_23 | AC | 77 ms
73,492 KB |
testcase_24 | AC | 90 ms
78,672 KB |
testcase_25 | AC | 94 ms
78,624 KB |
testcase_26 | AC | 92 ms
78,696 KB |
testcase_27 | AC | 79 ms
74,068 KB |
testcase_28 | AC | 82 ms
75,360 KB |
testcase_29 | AC | 92 ms
78,656 KB |
testcase_30 | AC | 93 ms
78,736 KB |
testcase_31 | AC | 97 ms
78,668 KB |
testcase_32 | AC | 98 ms
78,608 KB |
testcase_33 | AC | 82 ms
75,052 KB |
testcase_34 | AC | 93 ms
78,796 KB |
testcase_35 | AC | 97 ms
78,720 KB |
testcase_36 | AC | 69 ms
69,736 KB |
testcase_37 | AC | 68 ms
68,804 KB |
testcase_38 | AC | 68 ms
69,532 KB |
testcase_39 | AC | 67 ms
69,520 KB |
testcase_40 | AC | 68 ms
68,728 KB |
testcase_41 | AC | 69 ms
69,824 KB |
testcase_42 | AC | 68 ms
69,092 KB |
testcase_43 | AC | 68 ms
70,312 KB |
testcase_44 | AC | 67 ms
70,496 KB |
testcase_45 | AC | 68 ms
69,836 KB |
testcase_46 | AC | 68 ms
69,496 KB |
testcase_47 | AC | 68 ms
68,948 KB |
testcase_48 | AC | 68 ms
69,916 KB |
testcase_49 | AC | 68 ms
69,320 KB |
testcase_50 | AC | 67 ms
68,612 KB |
testcase_51 | AC | 68 ms
70,184 KB |
testcase_52 | AC | 68 ms
69,156 KB |
testcase_53 | AC | 68 ms
69,652 KB |
testcase_54 | AC | 68 ms
69,412 KB |
testcase_55 | AC | 68 ms
70,040 KB |
testcase_56 | AC | 68 ms
69,844 KB |
testcase_57 | AC | 68 ms
69,280 KB |
testcase_58 | AC | 67 ms
69,188 KB |
testcase_59 | AC | 66 ms
69,512 KB |
testcase_60 | AC | 68 ms
69,512 KB |
testcase_61 | AC | 67 ms
68,604 KB |
testcase_62 | AC | 68 ms
68,708 KB |
testcase_63 | AC | 67 ms
68,908 KB |
testcase_64 | AC | 67 ms
69,132 KB |
testcase_65 | AC | 67 ms
68,556 KB |
testcase_66 | AC | 68 ms
69,148 KB |
testcase_67 | AC | 69 ms
69,736 KB |
testcase_68 | AC | 68 ms
68,992 KB |
testcase_69 | AC | 69 ms
69,548 KB |
testcase_70 | AC | 68 ms
68,852 KB |
testcase_71 | AC | 68 ms
69,040 KB |
testcase_72 | AC | 67 ms
70,100 KB |
testcase_73 | AC | 67 ms
68,544 KB |
testcase_74 | AC | 67 ms
69,632 KB |
testcase_75 | AC | 68 ms
69,792 KB |
testcase_76 | AC | 68 ms
68,960 KB |
testcase_77 | AC | 66 ms
69,612 KB |
testcase_78 | AC | 68 ms
70,044 KB |
testcase_79 | AC | 68 ms
69,176 KB |
testcase_80 | AC | 69 ms
69,064 KB |
testcase_81 | AC | 68 ms
70,380 KB |
testcase_82 | AC | 69 ms
69,688 KB |
testcase_83 | AC | 68 ms
69,000 KB |
testcase_84 | AC | 69 ms
69,116 KB |
testcase_85 | AC | 69 ms
68,448 KB |
testcase_86 | AC | 72 ms
70,300 KB |
testcase_87 | AC | 70 ms
68,916 KB |
testcase_88 | AC | 68 ms
69,004 KB |
testcase_89 | AC | 70 ms
69,208 KB |
testcase_90 | AC | 69 ms
69,664 KB |
testcase_91 | AC | 69 ms
69,632 KB |
testcase_92 | AC | 68 ms
69,036 KB |
testcase_93 | AC | 68 ms
69,096 KB |
testcase_94 | AC | 67 ms
69,740 KB |
testcase_95 | AC | 68 ms
69,748 KB |
testcase_96 | AC | 68 ms
68,608 KB |
testcase_97 | AC | 68 ms
68,844 KB |
testcase_98 | AC | 68 ms
70,088 KB |
testcase_99 | AC | 67 ms
69,732 KB |
testcase_100 | AC | 69 ms
68,656 KB |
testcase_101 | AC | 86 ms
77,836 KB |
testcase_102 | AC | 66 ms
68,616 KB |
testcase_103 | AC | 66 ms
68,624 KB |
testcase_104 | AC | 66 ms
69,516 KB |
testcase_105 | AC | 66 ms
68,788 KB |
testcase_106 | AC | 66 ms
69,512 KB |
ソースコード
from random import randrange from queue import Queue def is_prime( n ): if n <= 1 or ( n > 2 and ~n & 1 ): return False if n == 2 or n == 3: return True for i in range( 100 ): a = randrange( 2, n - 1, 1 ) p = n - 1 if pow( a, p, n ) != 1: return False while ~p & 1: p >>= 1 x = pow( a, p, n ) if x == 1: continue if x == n - 1: break return False return True N = int( input() ) if N < 100: for w in range( 1, N + 1, 1 ): dd = [ -1, 1, -w, w ] vis = [ False for i in range( N + 1 ) ] que = Queue() vis[ 1 ] = True que.put( 1 ) while not que.empty(): u = que.get() if u == N: exit( print( w ) ) for di in range( 4 ): if di == 0 and ( u - 1 ) % w == 0: continue if di == 1 and u % w == 0: continue nu = u + dd[ di ] if not ( 1 <= nu and nu <= N ): continue if is_prime( nu ): continue if vis[ nu ]: continue vis[ nu ] = 1 que.put( nu ) else: if N % 8 != 1 or not is_prime( N - 8 ): print( 8 ) else: print( 14 )