結果

問題 No.658 テトラナッチ数列 Hard
ユーザー cielciel
提出日時 2017-12-27 20:22:19
言語 Ruby
(3.3.0)
結果
TLE  
実行時間 -
コード長 405 bytes
コンパイル時間 121 ms
コンパイル使用メモリ 11,424 KB
実行使用メモリ 19,772 KB
最終ジャッジ日時 2023-08-23 07:21:15
合計ジャッジ時間 4,567 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
15,368 KB
testcase_01 AC 80 ms
15,356 KB
testcase_02 AC 86 ms
15,480 KB
testcase_03 AC 136 ms
15,300 KB
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

M=17
def mul(a,b)
	r=a.size.times.map{[0]*b[0].size}
	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.to_i.times{
    n=gets.to_i
    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