結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,508 KB
testcase_01 AC 2 ms
4,448 KB
testcase_02 AC 2 ms
4,440 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 3 ms
4,472 KB
testcase_05 AC 2 ms
4,400 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 3 ms
4,560 KB
testcase_08 AC 2 ms
4,476 KB
testcase_09 AC 2 ms
4,436 KB
testcase_10 AC 3 ms
4,464 KB
testcase_11 AC 3 ms
4,472 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 3 ms
4,432 KB
testcase_14 AC 3 ms
4,460 KB
testcase_15 AC 3 ms
4,384 KB
testcase_16 AC 3 ms
4,384 KB
testcase_17 AC 2 ms
4,412 KB
testcase_18 AC 2 ms
4,384 KB
testcase_19 AC 3 ms
4,412 KB
testcase_20 AC 2 ms
4,396 KB
testcase_21 AC 2 ms
4,552 KB
testcase_22 AC 3 ms
4,436 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

lib C;fun strtoll(s: UInt8*,p: UInt8*,b: Int32): Int64;end
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=C.strtoll(gets.not_nil!,nil,10)
puts pow(n)*pow(n+1)%M
0