結果
| 問題 |
No.3127 Multiple of Twin Prime
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-04-25 23:04:02 |
| 言語 | Ruby (3.4.1) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,595 bytes |
| コンパイル時間 | 579 ms |
| コンパイル使用メモリ | 8,228 KB |
| 実行使用メモリ | 13,568 KB |
| 最終ジャッジ日時 | 2025-04-25 23:04:12 |
| 合計ジャッジ時間 | 4,655 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | RE * 1 |
| other | RE * 12 |
コンパイルメッセージ
Main.rb:34: warning: 'frozen_string_literal' is ignored after any tokens Syntax OK
ソースコード
# Kept libraries:
# - faster_prime
# Expanded libraries:
# - nanacl/bsearch_right
# Errored libraries:
# (none)
# Removed libraries:
# (none)
#
# ------------------------------------------------------------------------------
# frozen_string_literal: true
# This file is expanded by nanacl.
main = -> do # =================================================================
require "faster_prime"
# require "nanacl/bsearch_right" # (expanded: L22)
in_t = gets.chomp.to_i
twin_prime_multiples = []
primes = FasterPrime.each(10**7).to_a
primes.each_cons(2) { |p1, p2| twin_prime_multiples << p1 * p2 if p2 - p1 == 2 }
in_t.times do
in_n = gets.chomp.to_i
puts (twin_prime_multiples.bsearch_right { _1 <= in_n } || -1)
end
end # --------------------------------------------------------------------------
# === dependencies -------------------------------------------------------------
# == nanacl/bsearch_right from main --------------------------------------------
# frozen_string_literal: true
class Array
def bsearch_right(&)
index = bsearch_index_right(&)
index && self[index]
end
def bsearch_index_right(&block)
right = bsearch_index { |elem| !block.call(elem) }
if right.nil?
size - 1
elsif right == 0
nil
else
right - 1
end
end
end
class Range
def bsearch_right(&block)
right = bsearch { |elem| !block.call(elem) }
if right.nil?
last
elsif right == first
nil
else
right - 1
end
end
end
# ==============================================================================
main.call