結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
ユーザー letrangerjpletrangerjp
提出日時 2017-06-09 22:29:43
言語 Ruby
(3.3.0)
結果
AC  
実行時間 807 ms / 2,000 ms
コード長 135 bytes
コンパイル時間 52 ms
コンパイル使用メモリ 11,916 KB
実行使用メモリ 16,164 KB
最終ジャッジ日時 2023-10-23 21:48:22
合計ジャッジ時間 5,147 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

def fib(n)
  a = 0
  b = 1
  (n - 2).times{
    a, b = b, (a + b) % M
  }
  b
end

N, M = gets.split.take(2).map(&:to_i)

p fib(N) % M
0