結果

問題 No.658 テトラナッチ数列 Hard
ユーザー cielciel
提出日時 2017-12-29 19:17:59
言語 Crystal
(1.11.2)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 417 bytes
コンパイル時間 18,203 ms
コンパイル使用メモリ 256,380 KB
実行使用メモリ 5,360 KB
最終ジャッジ日時 2023-09-13 09:33:02
合計ジャッジ時間 22,833 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env crystal
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