結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
ユーザー gemmarogemmaro
提出日時 2019-11-15 09:05:54
言語 Ruby
(3.2.2)
結果
AC  
実行時間 332 ms / 2,000 ms
コード長 379 bytes
コンパイル時間 277 ms
コンパイル使用メモリ 11,872 KB
実行使用メモリ 16,072 KB
最終ジャッジ日時 2023-10-24 04:01:57
合計ジャッジ時間 3,570 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
16,072 KB
testcase_01 AC 80 ms
16,068 KB
testcase_02 AC 81 ms
16,072 KB
testcase_03 AC 80 ms
16,072 KB
testcase_04 AC 80 ms
16,072 KB
testcase_05 AC 80 ms
16,072 KB
testcase_06 AC 79 ms
16,072 KB
testcase_07 AC 80 ms
16,072 KB
testcase_08 AC 81 ms
16,072 KB
testcase_09 AC 86 ms
16,072 KB
testcase_10 AC 130 ms
16,072 KB
testcase_11 AC 327 ms
16,072 KB
testcase_12 AC 328 ms
16,072 KB
testcase_13 AC 329 ms
16,072 KB
testcase_14 AC 332 ms
16,072 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

# frozen_string_literal: true

n, m = gets.chomp.split.map(&:to_i)

def fib_mod(num, mod)
  i = 0
  b = 1
  c = 0
  while i < num
    a = b
    b = c
    c = (a + b) % mod
    i += 1
  end
  c
end
# ref: https://ja.wikipedia.org/%
#           wiki/%E3%83%95%E3%82%A3%E3%83%9C%E3%83%8A%E3%83%83%E3%83%81%E6%95%B0
#      https://yukicoder.me/submissions/246039

p fib_mod(n - 1, m)
0