結果
| 問題 | No.526 フィボナッチ数列の第N項をMで割った余りを求める | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2017-06-10 05:53:36 | 
| 言語 | Ruby (3.4.1) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 104 ms / 2,000 ms | 
| コード長 | 351 bytes | 
| コンパイル時間 | 45 ms | 
| コンパイル使用メモリ | 7,424 KB | 
| 実行使用メモリ | 13,056 KB | 
| 最終ジャッジ日時 | 2024-09-23 02:37:19 | 
| 合計ジャッジ時間 | 2,359 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 12 | 
コンパイルメッセージ
Syntax OK
ソースコード
# 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(n)
    if $memo.include? n
        $memo[n]
    else
        $memo[n] = (hoge(n/2)*hoge((n+1)/2)).map{|x|x%M}
    end
end
p hoge(N)[1,1]%M
            
            
            
        