結果

問題 No.658 テトラナッチ数列 Hard
ユーザー ngtkanangtkana
提出日時 2020-04-04 12:43:21
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 54 ms / 2,000 ms
コード長 1,320 bytes
コンパイル時間 2,310 ms
コンパイル使用メモリ 207,208 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-16 05:37:18
合計ジャッジ時間 3,260 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
using lint=long long;
using real=long double;
int main(){
    std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
    std::cout.setf(std::ios_base::fixed);std::cout.precision(15);
    lint mod=17;
    std::vector<lint>q={1,-1,-1,-1,-1},qinv={1,1,1,1},pa={1,-1,-1,-1};
    auto mul=[&,qdinv=-1](auto&&a,auto&&b){
        std::vector<lint>c(7);
        for(lint i=0;i<4;i++){
        for(lint j=0;j<4;j++){
            c.at(i+j)+=a.at(i)*b.at(j);
        }}
        while(4u<c.size()){
            lint x=-c.back()*qdinv;
            for(lint i=0;i<(lint)q.size();i++){
                c.at(c.size()-5+i)+=x*q.at(i);
            }
            assert(c.back()%mod==0);
            c.pop_back();
        }
        for(lint&x:c){
            x%=mod;
            if(x<0)x+=mod;
        }
        return c;
    };
    lint lg=63;
    std::vector<std::vector<lint>>table(lg);
    table.at(0)=qinv;
    for(lint i=1;i<lg;i++){
        table.at(i)=mul(table.at(i-1),table.at(i-1));
    }
    auto apow=[&](lint x){
        std::vector<lint>ans={1,0,0,0};
        for(lint i=0;i<lg;i++){
            if(x>>i&1)ans=mul(ans,table.at(i));
        };
        return ans;
    };
    lint t;std::cin>>t;
    while(t--){
        lint n;std::cin>>n;
        std::cout<<mul(apow(n),pa).at(0)<<'\n';
    }
}
0