結果

問題 No.308 素数は通れません
ユーザー 0w10w1
提出日時 2017-04-15 20:48:16
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 998 bytes
コンパイル時間 1,074 ms
コンパイル使用メモリ 86,772 KB
実行使用メモリ 84,176 KB
最終ジャッジ日時 2023-09-25 22:24:58
合計ジャッジ時間 25,939 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 198 ms
82,032 KB
testcase_01 AC 194 ms
82,092 KB
testcase_02 AC 201 ms
82,020 KB
testcase_03 AC 200 ms
81,884 KB
testcase_04 AC 201 ms
81,864 KB
testcase_05 AC 218 ms
82,868 KB
testcase_06 AC 211 ms
83,172 KB
testcase_07 AC 194 ms
82,052 KB
testcase_08 AC 192 ms
82,000 KB
testcase_09 AC 198 ms
83,364 KB
testcase_10 AC 215 ms
82,992 KB
testcase_11 WA -
testcase_12 AC 200 ms
83,024 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 215 ms
82,968 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 219 ms
83,004 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 218 ms
83,280 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 228 ms
84,176 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 224 ms
83,736 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 190 ms
82,136 KB
testcase_37 AC 194 ms
81,784 KB
testcase_38 AC 193 ms
81,900 KB
testcase_39 AC 191 ms
82,064 KB
testcase_40 AC 191 ms
81,828 KB
testcase_41 AC 194 ms
82,148 KB
testcase_42 AC 192 ms
82,104 KB
testcase_43 AC 193 ms
82,148 KB
testcase_44 AC 192 ms
81,832 KB
testcase_45 AC 194 ms
81,912 KB
testcase_46 AC 197 ms
81,824 KB
testcase_47 AC 193 ms
81,716 KB
testcase_48 AC 194 ms
82,096 KB
testcase_49 AC 193 ms
82,016 KB
testcase_50 AC 196 ms
81,768 KB
testcase_51 AC 196 ms
82,224 KB
testcase_52 AC 194 ms
82,048 KB
testcase_53 AC 193 ms
82,152 KB
testcase_54 AC 197 ms
82,108 KB
testcase_55 AC 195 ms
81,640 KB
testcase_56 AC 196 ms
81,832 KB
testcase_57 AC 193 ms
82,036 KB
testcase_58 AC 196 ms
82,064 KB
testcase_59 AC 197 ms
81,828 KB
testcase_60 AC 195 ms
81,928 KB
testcase_61 AC 192 ms
81,968 KB
testcase_62 AC 192 ms
81,924 KB
testcase_63 AC 199 ms
81,780 KB
testcase_64 AC 195 ms
82,056 KB
testcase_65 AC 190 ms
82,052 KB
testcase_66 AC 192 ms
82,136 KB
testcase_67 AC 196 ms
82,008 KB
testcase_68 AC 200 ms
82,140 KB
testcase_69 AC 199 ms
81,788 KB
testcase_70 AC 204 ms
81,772 KB
testcase_71 AC 195 ms
81,964 KB
testcase_72 AC 202 ms
82,060 KB
testcase_73 AC 202 ms
81,916 KB
testcase_74 AC 199 ms
81,836 KB
testcase_75 AC 195 ms
81,824 KB
testcase_76 AC 199 ms
82,048 KB
testcase_77 AC 198 ms
82,020 KB
testcase_78 AC 196 ms
81,908 KB
testcase_79 AC 195 ms
82,096 KB
testcase_80 AC 193 ms
82,108 KB
testcase_81 AC 200 ms
82,120 KB
testcase_82 AC 196 ms
81,784 KB
testcase_83 AC 196 ms
82,028 KB
testcase_84 AC 200 ms
81,960 KB
testcase_85 AC 202 ms
81,908 KB
testcase_86 AC 205 ms
82,124 KB
testcase_87 AC 201 ms
82,148 KB
testcase_88 AC 198 ms
82,036 KB
testcase_89 AC 204 ms
82,100 KB
testcase_90 AC 203 ms
82,028 KB
testcase_91 AC 202 ms
81,792 KB
testcase_92 AC 194 ms
82,068 KB
testcase_93 AC 197 ms
82,056 KB
testcase_94 AC 199 ms
82,148 KB
testcase_95 AC 194 ms
81,660 KB
testcase_96 AC 195 ms
82,032 KB
testcase_97 AC 193 ms
82,212 KB
testcase_98 AC 199 ms
82,036 KB
testcase_99 AC 192 ms
81,636 KB
testcase_100 AC 196 ms
81,644 KB
testcase_101 AC 206 ms
81,892 KB
testcase_102 AC 199 ms
82,048 KB
testcase_103 AC 200 ms
82,052 KB
testcase_104 AC 201 ms
82,036 KB
testcase_105 AC 199 ms
82,076 KB
testcase_106 AC 199 ms
82,132 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 ):
        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