結果

問題 No.6 使いものにならないハッシュ
ユーザー letrangerjpletrangerjp
提出日時 2017-05-14 14:09:41
言語 Ruby
(3.3.0)
結果
AC  
実行時間 149 ms / 5,000 ms
コード長 578 bytes
コンパイル時間 198 ms
コンパイル使用メモリ 11,552 KB
実行使用メモリ 16,412 KB
最終ジャッジ日時 2023-10-14 23:05:09
合計ジャッジ時間 5,416 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 86 ms
15,156 KB
testcase_01 AC 86 ms
15,324 KB
testcase_02 AC 149 ms
16,348 KB
testcase_03 AC 100 ms
15,600 KB
testcase_04 AC 109 ms
15,816 KB
testcase_05 AC 112 ms
15,788 KB
testcase_06 AC 135 ms
15,936 KB
testcase_07 AC 127 ms
16,004 KB
testcase_08 AC 129 ms
16,012 KB
testcase_09 AC 123 ms
15,840 KB
testcase_10 AC 86 ms
15,288 KB
testcase_11 AC 100 ms
15,340 KB
testcase_12 AC 140 ms
16,240 KB
testcase_13 AC 123 ms
15,948 KB
testcase_14 AC 125 ms
15,968 KB
testcase_15 AC 133 ms
16,176 KB
testcase_16 AC 128 ms
15,840 KB
testcase_17 AC 138 ms
15,848 KB
testcase_18 AC 146 ms
16,368 KB
testcase_19 AC 138 ms
16,084 KB
testcase_20 AC 136 ms
16,260 KB
testcase_21 AC 94 ms
15,484 KB
testcase_22 AC 135 ms
15,908 KB
testcase_23 AC 136 ms
16,412 KB
testcase_24 AC 136 ms
16,120 KB
testcase_25 AC 129 ms
16,044 KB
testcase_26 AC 141 ms
16,120 KB
testcase_27 AC 134 ms
16,132 KB
testcase_28 AC 115 ms
15,688 KB
testcase_29 AC 142 ms
16,132 KB
testcase_30 AC 140 ms
16,136 KB
testcase_31 AC 138 ms
15,884 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

require "prime"

def h(n)
  # while n > 10
  #   n = n.to_s.chars.map(&:to_i).inject(0,:+)
  # end
  # n
  while n > 10
    r = 0
    while n > 0
      n, m = n.divmod(10)
      r += m
    end
    n = r
  end
  n
end

def f(k, n)
  primes = Prime.each(n).drop_while{|n| n < k}

  last = -1
  max = 0
  r = []
  primes.each_with_index{|_v,i|
    # break if i + max > primes.size

    v = h(_v)
    idx = r.index(v)
    r.shift(idx+1) if idx
    r << v
    max = [max, r.size].max
    last = i if r.size >= max
  }
  primes[last-max+1]
end


K = gets.to_i
N = gets.to_i
p f(K, N)
0