結果

問題 No.718 行列のできるフィボナッチ数列道場 (1)
ユーザー cielciel
提出日時 2018-07-27 23:53:43
言語 Crystal
(1.11.2)
結果
RE  
実行時間 -
コード長 413 bytes
コンパイル時間 16,530 ms
コンパイル使用メモリ 256,692 KB
実行使用メモリ 4,776 KB
最終ジャッジ日時 2023-09-13 09:46:56
合計ジャッジ時間 17,918 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env crystal
M=1000000007
A=[[1_i64,1_i64],[1_i64,0_i64]]
E=[[1_i64,0_i64],[0_i64,1_i64]]
def mul(a,b)
	r=a.size.times.map{[0_i64]*b[0].size}.to_a
	a.size.times{|y|
		b[0].size.times{|x|
			r[y][x]=b.size.times.reduce(0){|s,i|(s+a[y][i]*b[i][x])%M}
		}
	}
	r
end
def pow(n)
	a=A
	e=E
	while n>0
		e=mul(a,e) if n%2>0
		a=mul(a,a)
		n/=2
	end
	e[-1][-1]
end
n=gets.not_nil!.to_i64
puts pow(n)*pow(n+1)%M
0