結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 94 ms
15,188 KB
testcase_01 AC 94 ms
15,356 KB
testcase_02 AC 201 ms
16,644 KB
testcase_03 AC 113 ms
16,076 KB
testcase_04 AC 128 ms
16,176 KB
testcase_05 AC 135 ms
16,180 KB
testcase_06 AC 163 ms
16,352 KB
testcase_07 AC 146 ms
16,600 KB
testcase_08 AC 157 ms
16,348 KB
testcase_09 AC 139 ms
16,640 KB
testcase_10 AC 92 ms
15,180 KB
testcase_11 AC 121 ms
16,320 KB
testcase_12 AC 178 ms
16,600 KB
testcase_13 AC 137 ms
16,568 KB
testcase_14 AC 139 ms
16,568 KB
testcase_15 AC 165 ms
16,600 KB
testcase_16 AC 150 ms
16,588 KB
testcase_17 AC 175 ms
16,436 KB
testcase_18 AC 195 ms
16,796 KB
testcase_19 AC 172 ms
16,484 KB
testcase_20 AC 168 ms
16,688 KB
testcase_21 AC 106 ms
15,912 KB
testcase_22 AC 172 ms
16,684 KB
testcase_23 AC 173 ms
16,920 KB
testcase_24 AC 175 ms
16,496 KB
testcase_25 AC 160 ms
16,588 KB
testcase_26 AC 184 ms
16,812 KB
testcase_27 AC 164 ms
16,496 KB
testcase_28 AC 136 ms
16,376 KB
testcase_29 AC 185 ms
16,600 KB
testcase_30 AC 180 ms
16,760 KB
testcase_31 AC 171 ms
16,356 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).select{|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