結果

問題 No.718 行列のできるフィボナッチ数列道場 (1)
ユーザー urutomurutom
提出日時 2019-04-04 16:34:06
言語 Ruby
(3.3.0)
結果
AC  
実行時間 85 ms / 2,000 ms
コード長 313 bytes
コンパイル時間 425 ms
コンパイル使用メモリ 11,188 KB
実行使用メモリ 15,404 KB
最終ジャッジ日時 2023-08-26 21:09:12
合計ジャッジ時間 4,002 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 82 ms
15,252 KB
testcase_01 AC 82 ms
15,340 KB
testcase_02 AC 83 ms
15,028 KB
testcase_03 AC 83 ms
15,308 KB
testcase_04 AC 82 ms
15,036 KB
testcase_05 AC 82 ms
15,140 KB
testcase_06 AC 83 ms
15,260 KB
testcase_07 AC 83 ms
15,148 KB
testcase_08 AC 82 ms
15,268 KB
testcase_09 AC 82 ms
15,128 KB
testcase_10 AC 82 ms
15,288 KB
testcase_11 AC 83 ms
15,088 KB
testcase_12 AC 84 ms
15,284 KB
testcase_13 AC 82 ms
15,352 KB
testcase_14 AC 84 ms
15,100 KB
testcase_15 AC 85 ms
15,084 KB
testcase_16 AC 83 ms
15,084 KB
testcase_17 AC 82 ms
15,004 KB
testcase_18 AC 84 ms
15,252 KB
testcase_19 AC 83 ms
15,344 KB
testcase_20 AC 81 ms
15,404 KB
testcase_21 AC 83 ms
15,260 KB
testcase_22 AC 84 ms
15,296 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

M=1000000007

def mul(a,b)
  2.times.map{|i|
    2.times.map{|j|
      2.times.map{|k|a[i][k]*b[k][j]}.inject(:+)%M
  }}
end

def fib(n)
  mat=[[1,1],[1,0]]
  prod=[[1,0],[0,1]]
  while n>0
    prod=mul(prod,mat) if n.odd?
    mat=mul(mat,mat)
    n/=2
  end
  prod[1][0]
end

n=gets.to_i
puts (fib(n)*fib(n+1))%M
0