結果

問題 No.658 テトラナッチ数列 Hard
ユーザー cielciel
提出日時 2020-02-08 22:21:27
言語 Crystal
(1.11.2)
結果
AC  
実行時間 840 ms / 2,000 ms
コード長 395 bytes
コンパイル時間 18,586 ms
コンパイル使用メモリ 255,440 KB
実行使用メモリ 5,228 KB
最終ジャッジ日時 2023-09-13 10:23:01
合計ジャッジ時間 22,539 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,500 KB
testcase_01 AC 3 ms
4,508 KB
testcase_02 AC 3 ms
4,648 KB
testcase_03 AC 5 ms
5,140 KB
testcase_04 AC 296 ms
5,228 KB
testcase_05 AC 343 ms
5,164 KB
testcase_06 AC 440 ms
5,084 KB
testcase_07 AC 470 ms
5,124 KB
testcase_08 AC 559 ms
5,144 KB
testcase_09 AC 835 ms
5,084 KB
testcase_10 AC 840 ms
5,088 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

M=17
def mul(a,b)
	r=a.size.times.map{[0]*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
A=[[1,1,1,1],[1,0,0,0],[0,1,0,0],[0,0,1,0]]
E=[[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]]
gets.not_nil!.to_i.times{
	n=gets.not_nil!.to_i64
	a=A
	e=E
	while n>0
		e=mul(a,e) if n%2>0
		a=mul(a,a)
		n//=2
	end
	p e[-1][-1]
}
0