結果

問題 No.6 使いものにならないハッシュ
ユーザー vjudge1
提出日時 2025-09-04 17:00:03
言語 Crystal
(1.14.0)
結果
RE  
実行時間 -
コード長 712 bytes
コンパイル時間 13,210 ms
コンパイル使用メモリ 309,840 KB
実行使用メモリ 7,720 KB
最終ジャッジ日時 2025-09-04 17:00:18
合計ジャッジ時間 14,057 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other RE * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

def digital_root(n : Int32) : Int32
  n == 0 ? 0 : 1 + (n - 1) % 9
end

# Read input
input = gets.not_nil!.split.map(&.to_i)
k = input[0]
n = input[1]

# Sieve of Eratosthenes
is_prime = Array.new(n + 1, true)
primes = [] of Int32

(2..n).each do |i|
  next unless is_prime[i]
  primes << i if k <= i
  j = i * 2
  while j <= n
    is_prime[j] = false
    j += i
  end
end

# Process primes with sliding window
que = Deque(Int32).new
v = Array.new(10, false)
mlen = 0
ans = 0

primes.each do |p|
  t = digital_root(p)
  
  while v[t]
    front = que.shift
    v[digital_root(front)] = false
  end
  
  que.push(p)
  v[t] = true
  
  if mlen <= que.size
    mlen = que.size
    ans = que.first
  end
end

puts ans
0