結果
問題 | No.658 テトラナッチ数列 Hard |
ユーザー |
![]() |
提出日時 | 2018-03-02 23:48:31 |
言語 | D (dmd 2.109.1) |
結果 |
AC
|
実行時間 | 51 ms / 2,000 ms |
コード長 | 1,278 bytes |
コンパイル時間 | 694 ms |
コンパイル使用メモリ | 100,904 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-13 00:01:09 |
合計ジャッジ時間 | 1,453 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 8 |
ソースコード
void main(){import std.stdio, std.string, std.conv, std.algorithm;const int mod=17;auto mat=new int[][][](64, 4, 4);mat[0][0][0]=1; mat[0][0][1]=1; mat[0][0][2]=1; mat[0][0][3]=1;mat[0][1][0]=1; mat[0][1][1]=0; mat[0][1][2]=0; mat[0][1][3]=0;mat[0][2][0]=0; mat[0][2][1]=1; mat[0][2][2]=0; mat[0][2][3]=0;mat[0][3][0]=0; mat[0][3][1]=0; mat[0][3][2]=1; mat[0][3][3]=0;foreach(t; 1..64){auto prev=mat[t-1], nex=mat[t];foreach(i; 0..4)foreach(j; 0..4){foreach(k; 0..4) (nex[i][j]+=prev[i][k]*prev[k][j])%=mod;}}int q; rd(q);while(q--){long n; rd(n);if(n<=3){writeln(0); continue;}if(n==4){writeln(1); continue;}auto a=new int[](4);a[0]=1; a[1]=0; a[2]=0; a[3]=0;n-=4;foreach(t; 0..64)if(n&(1L<<t)){auto b=new int[](4);foreach(i; 0..4)foreach(j; 0..4) (b[i]+=mat[t][i][j]*a[j])%=mod;a.swap(b);}writeln(a[0]);}}/+a5 1 1 1 1 a4a4 = 1 0 0 0 a3a3 0 1 0 0 a2a2 0 0 1 0 a1a1=a2=a3=0, a4=1a5 ... T ... 001a6 ... T^2 ... 010a7 ... T^3 ... 011+/void rd(T...)(ref T x){import std.stdio, std.string, std.conv;auto l=readln.split;assert(l.length==x.length);foreach(i, ref e; x){e=l[i].to!(typeof(e));}}