結果

問題 No.718 行列のできるフィボナッチ数列道場 (1)
ユーザー cielciel
提出日時 2020-02-08 22:26:01
言語 Crystal
(1.11.2)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 392 bytes
コンパイル時間 17,340 ms
コンパイル使用メモリ 256,148 KB
実行使用メモリ 4,516 KB
最終ジャッジ日時 2023-09-13 10:24:16
合計ジャッジ時間 18,477 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,424 KB
testcase_01 AC 2 ms
4,500 KB
testcase_02 AC 3 ms
4,516 KB
testcase_03 AC 3 ms
4,432 KB
testcase_04 AC 3 ms
4,384 KB
testcase_05 AC 2 ms
4,460 KB
testcase_06 AC 2 ms
4,452 KB
testcase_07 AC 3 ms
4,424 KB
testcase_08 AC 2 ms
4,492 KB
testcase_09 AC 3 ms
4,504 KB
testcase_10 AC 2 ms
4,484 KB
testcase_11 AC 3 ms
4,380 KB
testcase_12 AC 3 ms
4,388 KB
testcase_13 AC 2 ms
4,476 KB
testcase_14 AC 3 ms
4,404 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 3 ms
4,380 KB
testcase_17 AC 3 ms
4,380 KB
testcase_18 AC 2 ms
4,412 KB
testcase_19 AC 3 ms
4,492 KB
testcase_20 AC 3 ms
4,380 KB
testcase_21 AC 3 ms
4,444 KB
testcase_22 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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_i64){|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[0][1]
end
n=gets.not_nil!.to_i64
puts pow(n)*pow(n+1)%M
0