結果
| 問題 | No.526 フィボナッチ数列の第N項をMで割った余りを求める |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-06-10 05:53:36 |
| 言語 | Ruby (4.0.2) |
| 結果 |
AC
|
| 実行時間 | 62 ms / 2,000 ms |
| コード長 | 351 bytes |
| 記録 | |
| コンパイル時間 | 248 ms |
| コンパイル使用メモリ | 8,704 KB |
| 実行使用メモリ | 15,744 KB |
| 最終ジャッジ日時 | 2026-04-11 08:03:18 |
| 合計ジャッジ時間 | 2,042 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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