結果

問題 No.843 Triple Primes
ユーザー pekempeypekempey
提出日時 2019-06-29 19:42:54
言語 Ruby
(3.3.0)
結果
AC  
実行時間 335 ms / 2,000 ms
コード長 331 bytes
コンパイル時間 397 ms
コンパイル使用メモリ 11,896 KB
実行使用メモリ 20,648 KB
最終ジャッジ日時 2023-10-19 17:56:45
合計ジャッジ時間 15,421 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 277 ms
20,124 KB
testcase_01 AC 320 ms
20,648 KB
testcase_02 AC 274 ms
20,124 KB
testcase_03 AC 276 ms
20,124 KB
testcase_04 AC 280 ms
20,124 KB
testcase_05 AC 278 ms
20,128 KB
testcase_06 AC 272 ms
20,124 KB
testcase_07 AC 314 ms
20,384 KB
testcase_08 AC 321 ms
20,384 KB
testcase_09 AC 326 ms
20,648 KB
testcase_10 AC 316 ms
20,384 KB
testcase_11 AC 325 ms
20,648 KB
testcase_12 AC 320 ms
20,648 KB
testcase_13 AC 316 ms
20,648 KB
testcase_14 AC 330 ms
20,648 KB
testcase_15 AC 306 ms
20,384 KB
testcase_16 AC 314 ms
20,384 KB
testcase_17 AC 275 ms
20,124 KB
testcase_18 AC 275 ms
20,124 KB
testcase_19 AC 277 ms
20,124 KB
testcase_20 AC 291 ms
20,124 KB
testcase_21 AC 281 ms
20,124 KB
testcase_22 AC 303 ms
20,384 KB
testcase_23 AC 301 ms
20,384 KB
testcase_24 AC 291 ms
20,124 KB
testcase_25 AC 292 ms
20,124 KB
testcase_26 AC 327 ms
20,648 KB
testcase_27 AC 284 ms
20,128 KB
testcase_28 AC 317 ms
20,648 KB
testcase_29 AC 292 ms
20,124 KB
testcase_30 AC 335 ms
20,648 KB
testcase_31 AC 289 ms
20,128 KB
testcase_32 AC 284 ms
20,124 KB
testcase_33 AC 286 ms
20,124 KB
testcase_34 AC 302 ms
20,172 KB
testcase_35 AC 322 ms
20,648 KB
testcase_36 AC 287 ms
20,124 KB
testcase_37 AC 318 ms
20,392 KB
testcase_38 AC 306 ms
20,384 KB
testcase_39 AC 327 ms
20,648 KB
testcase_40 AC 268 ms
20,124 KB
testcase_41 AC 269 ms
20,124 KB
testcase_42 AC 323 ms
20,384 KB
testcase_43 AC 335 ms
20,648 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

table = [true] * 500001
table[0] = table[1] = false

for i in 2..500000
  if table[i]
    for j in 2..500000/i
      table[i*j] = false
    end
  end
end

n = gets.to_i
(puts 0; exit) if n == 1

ans = 1
(2..n).select{|i| table[i]}.each do |r|
  p = 2
  q = r**2-p
  if 3 <= q && q <= n && table[q]
    ans += 2
  end
end

puts ans
0