結果

問題 No.658 テトラナッチ数列 Hard
ユーザー 夕叢霧香(ゆうむらきりか)夕叢霧香(ゆうむらきりか)
提出日時 2018-03-02 22:32:25
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 300 ms / 2,000 ms
コード長 920 bytes
コンパイル時間 2,157 ms
コンパイル使用メモリ 75,012 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-03 23:15:06
合計ジャッジ時間 4,787 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 4 ms
4,376 KB
testcase_04 AC 240 ms
4,380 KB
testcase_05 AC 247 ms
4,380 KB
testcase_06 AC 255 ms
4,376 KB
testcase_07 AC 258 ms
4,380 KB
testcase_08 AC 267 ms
4,376 KB
testcase_09 AC 300 ms
4,376 KB
testcase_10 AC 300 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<algorithm>
#include<iostream>
#include<vector>
using namespace std;
typedef long long lint;
typedef vector<int>vi;
typedef pair<int,int>pii;
#define rep(i,n)for(int i=0;i<(int)(n);++i)

const int A=4;


vector<vi> mul(const vector<vi> &a,const vector<vi> &b){
  vector<vi> ret(A, vi(A));
  rep(i,A){
    rep(j,A){
      rep(k,A){
	ret[i][j]+=a[i][k]*b[k][j];
	ret[i][j]%=17;
      }
    }
  }
  return ret;
}

vector<vi> pow(const vector<vi> &a,lint e){
  vector<vi> cur(A,vi(A,0));
  rep(i,A)cur[i][i]=1;
  for(int i=63;i>=0;--i){
    cur=mul(cur,cur);
    if(e&1LL<<i)cur=mul(cur,a);
  }
  return cur;
}

int main(){
  int q;
  cin>>q;
  rep(_,q){
    lint n;
    cin>>n;
    vector<vi> a(A,vi(A));
    rep(i,A)a[A-1][i]=1;
    rep(i,A-1)a[i][i+1]=1;
    vector<vi> t=pow(a,n);
    if(0){
    rep(i,A){
      rep(j,A){
	cerr<<t[i][j]<<" ";
      }
      cerr<<endl;
    }
    }
    cout<<t[0][0]<<endl;
  }
}
0