結果

問題 No.2363 k-bonacci
ユーザー siman
提出日時 2023-06-30 16:26:02
言語 Ruby
(4.0.2)
コンパイル:
ruby -w -c _filename_
実行:
ruby _filename_
結果
WA  
実行時間 -
コード長 337 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 101 ms
コンパイル使用メモリ 8,960 KB
実行使用メモリ 15,104 KB
最終ジャッジ日時 2026-03-28 18:32:51
合計ジャッジ時間 3,718 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 38 WA * 1
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:33: warning: ambiguous first argument; put parentheses or a space even after `-` operator
Syntax OK

ソースコード

diff #
raw source code

N = gets.to_i

def k_fib(k)
  nums = [0] * (k - 1)
  nums << 1
  sum = 1

  while nums.last < N
    l = nums.size
    nums << sum
    sum -= nums[l - k]
    sum += nums.last

    if nums.last == N
      return true
    end
  end

  false
end

k = 2

while 2 ** (k - 1) <= N
  if k_fib(k)
    puts k
    exit
  end

  k += 1
end

puts -1
0