結果

問題 No.308 素数は通れません
ユーザー 0w10w1
提出日時 2017-04-15 20:39:06
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 971 bytes
コンパイル時間 445 ms
コンパイル使用メモリ 86,948 KB
実行使用メモリ 83,600 KB
最終ジャッジ日時 2023-09-25 22:23:54
合計ジャッジ時間 25,403 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 185 ms
81,756 KB
testcase_01 AC 185 ms
82,184 KB
testcase_02 AC 191 ms
81,788 KB
testcase_03 AC 193 ms
81,748 KB
testcase_04 AC 189 ms
81,832 KB
testcase_05 AC 199 ms
82,940 KB
testcase_06 AC 195 ms
83,464 KB
testcase_07 AC 188 ms
83,132 KB
testcase_08 AC 190 ms
83,028 KB
testcase_09 WA -
testcase_10 AC 202 ms
83,356 KB
testcase_11 WA -
testcase_12 AC 189 ms
83,368 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 204 ms
83,464 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 203 ms
83,136 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 202 ms
83,360 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 182 ms
81,776 KB
testcase_37 AC 186 ms
82,124 KB
testcase_38 AC 181 ms
82,180 KB
testcase_39 AC 183 ms
82,168 KB
testcase_40 AC 185 ms
82,176 KB
testcase_41 AC 187 ms
81,956 KB
testcase_42 AC 186 ms
82,232 KB
testcase_43 AC 181 ms
81,976 KB
testcase_44 AC 184 ms
82,080 KB
testcase_45 AC 187 ms
82,188 KB
testcase_46 AC 183 ms
81,780 KB
testcase_47 AC 185 ms
82,232 KB
testcase_48 AC 182 ms
82,076 KB
testcase_49 AC 184 ms
82,244 KB
testcase_50 AC 186 ms
81,776 KB
testcase_51 AC 183 ms
81,944 KB
testcase_52 AC 185 ms
82,100 KB
testcase_53 AC 189 ms
82,120 KB
testcase_54 AC 181 ms
82,208 KB
testcase_55 AC 184 ms
82,228 KB
testcase_56 AC 180 ms
81,900 KB
testcase_57 AC 185 ms
81,772 KB
testcase_58 AC 185 ms
82,228 KB
testcase_59 AC 182 ms
81,960 KB
testcase_60 AC 184 ms
82,172 KB
testcase_61 AC 185 ms
82,108 KB
testcase_62 AC 183 ms
82,060 KB
testcase_63 AC 187 ms
81,896 KB
testcase_64 AC 191 ms
82,228 KB
testcase_65 AC 185 ms
82,220 KB
testcase_66 AC 181 ms
81,900 KB
testcase_67 AC 181 ms
82,108 KB
testcase_68 AC 185 ms
82,128 KB
testcase_69 AC 185 ms
82,120 KB
testcase_70 AC 185 ms
82,008 KB
testcase_71 AC 181 ms
81,760 KB
testcase_72 AC 181 ms
82,040 KB
testcase_73 AC 183 ms
82,168 KB
testcase_74 AC 185 ms
82,228 KB
testcase_75 AC 182 ms
82,220 KB
testcase_76 WA -
testcase_77 AC 182 ms
82,192 KB
testcase_78 AC 186 ms
82,056 KB
testcase_79 AC 186 ms
82,112 KB
testcase_80 WA -
testcase_81 WA -
testcase_82 AC 184 ms
82,196 KB
testcase_83 AC 186 ms
82,188 KB
testcase_84 WA -
testcase_85 AC 182 ms
82,080 KB
testcase_86 WA -
testcase_87 WA -
testcase_88 AC 189 ms
81,900 KB
testcase_89 AC 183 ms
82,096 KB
testcase_90 WA -
testcase_91 AC 185 ms
81,772 KB
testcase_92 AC 185 ms
82,088 KB
testcase_93 AC 186 ms
82,224 KB
testcase_94 AC 188 ms
82,084 KB
testcase_95 AC 181 ms
82,080 KB
testcase_96 AC 187 ms
82,084 KB
testcase_97 AC 183 ms
82,180 KB
testcase_98 AC 185 ms
82,052 KB
testcase_99 AC 183 ms
81,908 KB
testcase_100 AC 181 ms
81,772 KB
testcase_101 WA -
testcase_102 AC 181 ms
82,132 KB
testcase_103 AC 181 ms
81,940 KB
testcase_104 AC 183 ms
81,876 KB
testcase_105 AC 183 ms
82,180 KB
testcase_106 AC 183 ms
81,984 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:
      x = pow( a, p, n )
      if x != 1 and x != n - 1: return False
      p >>= 1
  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 ):
        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