結果

問題 No.658 テトラナッチ数列 Hard
ユーザー cielciel
提出日時 2020-08-14 01:26:24
言語 Crystal
(1.11.2)
結果
AC  
実行時間 845 ms / 2,000 ms
コード長 465 bytes
コンパイル時間 18,056 ms
コンパイル使用メモリ 256,276 KB
実行使用メモリ 5,192 KB
最終ジャッジ日時 2023-09-13 11:39:01
合計ジャッジ時間 22,658 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,396 KB
testcase_01 AC 2 ms
4,476 KB
testcase_02 AC 3 ms
4,704 KB
testcase_03 AC 5 ms
5,032 KB
testcase_04 AC 298 ms
5,032 KB
testcase_05 AC 346 ms
5,192 KB
testcase_06 AC 439 ms
5,028 KB
testcase_07 AC 473 ms
5,172 KB
testcase_08 AC 551 ms
5,044 KB
testcase_09 AC 843 ms
5,108 KB
testcase_10 AC 845 ms
5,116 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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