結果

問題 No.843 Triple Primes
ユーザー TANIGUCHI KousukeTANIGUCHI Kousuke
提出日時 2019-12-12 10:27:48
言語 Ruby
(3.3.0)
結果
AC  
実行時間 228 ms / 2,000 ms
コード長 228 bytes
コンパイル時間 392 ms
コンパイル使用メモリ 11,436 KB
実行使用メモリ 18,392 KB
最終ジャッジ日時 2023-09-07 01:41:53
合計ジャッジ時間 11,284 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 94 ms
15,212 KB
testcase_01 AC 228 ms
18,112 KB
testcase_02 AC 94 ms
15,360 KB
testcase_03 AC 95 ms
15,276 KB
testcase_04 AC 96 ms
15,416 KB
testcase_05 AC 95 ms
15,056 KB
testcase_06 AC 94 ms
15,276 KB
testcase_07 AC 226 ms
18,200 KB
testcase_08 AC 228 ms
18,160 KB
testcase_09 AC 228 ms
18,048 KB
testcase_10 AC 225 ms
18,312 KB
testcase_11 AC 227 ms
18,116 KB
testcase_12 AC 227 ms
18,268 KB
testcase_13 AC 226 ms
18,088 KB
testcase_14 AC 228 ms
18,332 KB
testcase_15 AC 225 ms
18,116 KB
testcase_16 AC 226 ms
18,088 KB
testcase_17 AC 91 ms
15,276 KB
testcase_18 AC 92 ms
15,304 KB
testcase_19 AC 93 ms
15,360 KB
testcase_20 AC 128 ms
16,180 KB
testcase_21 AC 113 ms
15,792 KB
testcase_22 AC 161 ms
16,940 KB
testcase_23 AC 162 ms
16,732 KB
testcase_24 AC 129 ms
16,472 KB
testcase_25 AC 128 ms
16,440 KB
testcase_26 AC 225 ms
18,096 KB
testcase_27 AC 103 ms
15,348 KB
testcase_28 AC 227 ms
18,172 KB
testcase_29 AC 129 ms
16,440 KB
testcase_30 AC 225 ms
18,180 KB
testcase_31 AC 101 ms
15,448 KB
testcase_32 AC 96 ms
15,528 KB
testcase_33 AC 129 ms
16,136 KB
testcase_34 AC 162 ms
16,852 KB
testcase_35 AC 227 ms
18,180 KB
testcase_36 AC 110 ms
15,652 KB
testcase_37 AC 161 ms
16,768 KB
testcase_38 AC 160 ms
16,812 KB
testcase_39 AC 226 ms
18,304 KB
testcase_40 AC 91 ms
15,148 KB
testcase_41 AC 91 ms
15,196 KB
testcase_42 AC 226 ms
18,332 KB
testcase_43 AC 227 ms
18,392 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

require 'prime'

N = gets.to_i
P = Prime.each(N).to_a
P.shift # drop 2

ans = P.inject(1) do |s, r|
  r2 = r * r
  break s if r2 > N + 2
  q = P.bsearch{|x| x + 2 >= r2 }
  q && q + 2 == r2 ? s + 2 : s
end

puts N == 1 ? 0 : ans
0