結果

問題 No.6 使いものにならないハッシュ
ユーザー letrangerjpletrangerjp
提出日時 2017-05-14 14:09:07
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 576 bytes
コンパイル時間 215 ms
コンパイル使用メモリ 11,540 KB
実行使用メモリ 16,460 KB
最終ジャッジ日時 2023-10-14 10:56:29
合計ジャッジ時間 6,666 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 86 ms
15,172 KB
testcase_02 AC 147 ms
16,432 KB
testcase_03 AC 99 ms
15,452 KB
testcase_04 AC 108 ms
15,644 KB
testcase_05 WA -
testcase_06 AC 134 ms
16,052 KB
testcase_07 AC 127 ms
15,996 KB
testcase_08 WA -
testcase_09 AC 125 ms
15,876 KB
testcase_10 AC 87 ms
15,248 KB
testcase_11 AC 101 ms
15,432 KB
testcase_12 AC 138 ms
16,460 KB
testcase_13 AC 123 ms
15,952 KB
testcase_14 AC 124 ms
15,968 KB
testcase_15 AC 133 ms
16,324 KB
testcase_16 AC 128 ms
15,868 KB
testcase_17 AC 139 ms
16,100 KB
testcase_18 AC 147 ms
16,428 KB
testcase_19 AC 138 ms
15,948 KB
testcase_20 AC 136 ms
16,208 KB
testcase_21 AC 93 ms
15,380 KB
testcase_22 AC 136 ms
16,092 KB
testcase_23 AC 136 ms
16,428 KB
testcase_24 AC 136 ms
16,008 KB
testcase_25 AC 127 ms
15,928 KB
testcase_26 WA -
testcase_27 AC 135 ms
16,004 KB
testcase_28 AC 113 ms
15,836 KB
testcase_29 AC 145 ms
16,140 KB
testcase_30 WA -
testcase_31 AC 141 ms
15,972 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