結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
ユーザー LeonardoneLeonardone
提出日時 2017-06-10 05:16:56
言語 Ruby
(3.3.0)
結果
AC  
実行時間 114 ms / 2,000 ms
コード長 363 bytes
コンパイル時間 53 ms
コンパイル使用メモリ 11,876 KB
実行使用メモリ 16,736 KB
最終ジャッジ日時 2023-10-24 10:03:11
合計ジャッジ時間 2,455 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 114 ms
16,736 KB
testcase_01 AC 109 ms
16,736 KB
testcase_02 AC 109 ms
16,736 KB
testcase_03 AC 106 ms
16,736 KB
testcase_04 AC 111 ms
16,736 KB
testcase_05 AC 105 ms
16,736 KB
testcase_06 AC 106 ms
16,736 KB
testcase_07 AC 105 ms
16,736 KB
testcase_08 AC 103 ms
16,736 KB
testcase_09 AC 104 ms
16,736 KB
testcase_10 AC 103 ms
16,736 KB
testcase_11 AC 104 ms
16,736 KB
testcase_12 AC 103 ms
16,736 KB
testcase_13 AC 104 ms
16,736 KB
testcase_14 AC 103 ms
16,736 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

# yukicoder My Practice
# author: Leonardone @ NEETSDKASU

require 'matrix'

N, M = gets.strip.split.map &:to_i

mat = Matrix[[1, 1], [1, 0]]

$memo = {}
$memo[1] = mat
$memo[2] = (mat*mat).map{|x|x%M}

def hoge(a, n)
    if $memo.include? n
        $memo[n]
    else
        $memo[n] = (hoge(a,n/2)*hoge(a,(n+1)/2)).map{|x|x%M}
    end
end

p hoge(mat, N)[1,1]%M
0