結果

問題 No.308 素数は通れません
ユーザー 0w10w1
提出日時 2017-04-15 20:52:34
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 198 ms / 1,000 ms
コード長 1,093 bytes
コンパイル時間 334 ms
コンパイル使用メモリ 87,004 KB
実行使用メモリ 84,288 KB
最終ジャッジ日時 2023-08-18 13:31:50
合計ジャッジ時間 21,047 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 170 ms
82,164 KB
testcase_01 AC 168 ms
82,232 KB
testcase_02 AC 170 ms
81,856 KB
testcase_03 AC 165 ms
82,144 KB
testcase_04 AC 167 ms
81,984 KB
testcase_05 AC 167 ms
82,144 KB
testcase_06 AC 172 ms
83,152 KB
testcase_07 AC 166 ms
82,088 KB
testcase_08 AC 166 ms
82,016 KB
testcase_09 AC 173 ms
83,144 KB
testcase_10 AC 181 ms
83,080 KB
testcase_11 AC 197 ms
83,396 KB
testcase_12 AC 186 ms
82,028 KB
testcase_13 AC 198 ms
83,216 KB
testcase_14 AC 192 ms
83,212 KB
testcase_15 AC 172 ms
83,648 KB
testcase_16 AC 175 ms
83,472 KB
testcase_17 AC 171 ms
83,160 KB
testcase_18 AC 177 ms
83,616 KB
testcase_19 AC 184 ms
83,508 KB
testcase_20 AC 174 ms
83,452 KB
testcase_21 AC 174 ms
83,220 KB
testcase_22 AC 168 ms
83,244 KB
testcase_23 AC 173 ms
83,624 KB
testcase_24 AC 180 ms
83,724 KB
testcase_25 AC 188 ms
83,416 KB
testcase_26 AC 184 ms
83,240 KB
testcase_27 AC 176 ms
83,572 KB
testcase_28 AC 181 ms
83,380 KB
testcase_29 AC 182 ms
83,248 KB
testcase_30 AC 180 ms
83,596 KB
testcase_31 AC 185 ms
83,132 KB
testcase_32 AC 187 ms
84,288 KB
testcase_33 AC 175 ms
83,696 KB
testcase_34 AC 180 ms
83,264 KB
testcase_35 AC 182 ms
83,480 KB
testcase_36 AC 169 ms
82,060 KB
testcase_37 AC 165 ms
81,816 KB
testcase_38 AC 167 ms
81,940 KB
testcase_39 AC 161 ms
82,120 KB
testcase_40 AC 158 ms
82,128 KB
testcase_41 AC 157 ms
82,300 KB
testcase_42 AC 156 ms
82,192 KB
testcase_43 AC 158 ms
82,108 KB
testcase_44 AC 157 ms
82,212 KB
testcase_45 AC 154 ms
82,052 KB
testcase_46 AC 153 ms
82,172 KB
testcase_47 AC 152 ms
82,124 KB
testcase_48 AC 150 ms
82,172 KB
testcase_49 AC 153 ms
82,240 KB
testcase_50 AC 159 ms
82,104 KB
testcase_51 AC 154 ms
82,232 KB
testcase_52 AC 153 ms
82,232 KB
testcase_53 AC 153 ms
82,180 KB
testcase_54 AC 156 ms
81,988 KB
testcase_55 AC 151 ms
82,152 KB
testcase_56 AC 156 ms
82,124 KB
testcase_57 AC 152 ms
81,920 KB
testcase_58 AC 158 ms
82,200 KB
testcase_59 AC 150 ms
82,120 KB
testcase_60 AC 152 ms
82,256 KB
testcase_61 AC 151 ms
82,092 KB
testcase_62 AC 152 ms
82,236 KB
testcase_63 AC 153 ms
82,320 KB
testcase_64 AC 153 ms
82,232 KB
testcase_65 AC 154 ms
82,320 KB
testcase_66 AC 152 ms
82,208 KB
testcase_67 AC 168 ms
82,148 KB
testcase_68 AC 160 ms
82,048 KB
testcase_69 AC 154 ms
82,228 KB
testcase_70 AC 152 ms
82,272 KB
testcase_71 AC 153 ms
82,064 KB
testcase_72 AC 152 ms
82,232 KB
testcase_73 AC 160 ms
82,120 KB
testcase_74 AC 153 ms
81,980 KB
testcase_75 AC 157 ms
82,220 KB
testcase_76 AC 153 ms
82,100 KB
testcase_77 AC 156 ms
82,044 KB
testcase_78 AC 154 ms
82,172 KB
testcase_79 AC 154 ms
82,288 KB
testcase_80 AC 158 ms
81,920 KB
testcase_81 AC 159 ms
82,052 KB
testcase_82 AC 155 ms
82,220 KB
testcase_83 AC 167 ms
82,208 KB
testcase_84 AC 168 ms
82,064 KB
testcase_85 AC 157 ms
82,044 KB
testcase_86 AC 162 ms
81,972 KB
testcase_87 AC 165 ms
82,188 KB
testcase_88 AC 156 ms
82,232 KB
testcase_89 AC 160 ms
81,900 KB
testcase_90 AC 167 ms
82,208 KB
testcase_91 AC 164 ms
82,088 KB
testcase_92 AC 162 ms
82,056 KB
testcase_93 AC 161 ms
82,240 KB
testcase_94 AC 156 ms
82,056 KB
testcase_95 AC 154 ms
82,128 KB
testcase_96 AC 155 ms
81,924 KB
testcase_97 AC 152 ms
82,204 KB
testcase_98 AC 153 ms
82,216 KB
testcase_99 AC 157 ms
81,920 KB
testcase_100 AC 155 ms
82,304 KB
testcase_101 AC 162 ms
82,320 KB
testcase_102 AC 159 ms
82,236 KB
testcase_103 AC 156 ms
82,160 KB
testcase_104 AC 153 ms
81,800 KB
testcase_105 AC 154 ms
82,152 KB
testcase_106 AC 154 ms
81,928 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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 )
0