孤独な素数(私はそれらを呼ぶ)は素数であり、widthの数グリッドが与えられた場合w ≥ 3
、直交または対角線上に他の素数が隣接しない素数です。
たとえば、次の場所でグリッドを取得した場合w = 12
(太字で強調されたプライム):
1 2 3 4 5 6 7 8 9 10 11 12
13 14 15 16 17 18 19 20 21 22 23...
...86 87 88 89 90 91 92 93 94 95 96
97 98 99 100 101 102 103 104 105 106 107 108
109 110 111 112 113 114 115 116 117 118 119 120
2つの素数103と107のみが直交または対角線上に素数を持たないことがわかります。そこには孤独な素数がないため、セクションをスキップしました。(実際には37を除く)
あなたの仕事は、2つの入力w ≥ 3
とを与えられi ≥ 1
、幅を持つ数グリッドの最初の孤独な素数を決定するw
ことi
です。ここで、孤独な素数は以上でなければなりません。入力は、合理的な形式で取得できます(文字列としての取得を含む)。幅に対して孤独な素数があることが保証されますw
。
グリッドは回り込みません。
例:
w i output
11 5 11
12 104 107
12 157 157
9 1 151
12 12 37
これはcode-golfなので、最短のコードが勝ちます!
w=12
はない37
のですか?それを取り巻く数字はどれ{25, 26, 38, 49, 50}
も素数ではありません。