結果

問題 No.6 使いものにならないハッシュ
ユーザー neko_the_shadowneko_the_shadow
提出日時 2019-05-29 15:06:56
言語 Ruby
(3.3.0)
結果
AC  
実行時間 214 ms / 5,000 ms
コード長 441 bytes
コンパイル時間 256 ms
コンパイル使用メモリ 11,532 KB
実行使用メモリ 16,868 KB
最終ジャッジ日時 2023-10-14 23:17:14
合計ジャッジ時間 6,451 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 97 ms
15,280 KB
testcase_01 AC 98 ms
15,376 KB
testcase_02 AC 214 ms
16,632 KB
testcase_03 AC 119 ms
16,048 KB
testcase_04 AC 125 ms
16,252 KB
testcase_05 AC 133 ms
16,272 KB
testcase_06 AC 166 ms
16,496 KB
testcase_07 AC 146 ms
16,440 KB
testcase_08 AC 156 ms
16,412 KB
testcase_09 AC 136 ms
16,688 KB
testcase_10 AC 91 ms
15,212 KB
testcase_11 AC 114 ms
16,180 KB
testcase_12 AC 175 ms
16,768 KB
testcase_13 AC 139 ms
16,348 KB
testcase_14 AC 142 ms
16,464 KB
testcase_15 AC 167 ms
16,720 KB
testcase_16 AC 149 ms
16,440 KB
testcase_17 AC 176 ms
16,348 KB
testcase_18 AC 200 ms
16,812 KB
testcase_19 AC 178 ms
16,432 KB
testcase_20 AC 172 ms
16,600 KB
testcase_21 AC 110 ms
15,796 KB
testcase_22 AC 173 ms
16,456 KB
testcase_23 AC 175 ms
16,868 KB
testcase_24 AC 176 ms
16,376 KB
testcase_25 AC 151 ms
16,432 KB
testcase_26 AC 181 ms
16,532 KB
testcase_27 AC 167 ms
16,408 KB
testcase_28 AC 141 ms
16,324 KB
testcase_29 AC 187 ms
16,576 KB
testcase_30 AC 183 ms
16,740 KB
testcase_31 AC 174 ms
16,364 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

require "prime"

def to_hash(x)
  x = x.digits.sum until x < 10
  x
end

k = gets.to_i
n = gets.to_i

primes = Prime.each(n).filter{|prime| k <= prime}.to_a

answers = Hash.new(-1)
primes.size.times do |x|
  hashes = []
  (x...primes.size).each do |y|
    hash = to_hash(primes[y])
    break if hashes.include?(hash)
    hashes << hash
  end
  answers[hashes.size] = [answers[hashes.size], x].max 
end

puts primes[answers[answers.keys.max]]
0