結果

問題 No.3036 Restricted Lucas (Easy)
ユーザー みしあみしあ
提出日時 2021-10-22 12:08:01
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 6 ms / 2,000 ms
コード長 1,760 bytes
コンパイル時間 1,007 ms
コンパイル使用メモリ 73,152 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-23 20:11:56
合計ジャッジ時間 2,009 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 6 ms
4,348 KB
testcase_03 AC 5 ms
4,348 KB
testcase_04 AC 5 ms
4,348 KB
testcase_05 AC 5 ms
4,348 KB
testcase_06 AC 5 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <utility>
using namespace std;

using ll = long long;

const ll t = true, f = false;

template<class... Args>
ll Num(Args... args){
    ll ret = f;
    for(auto v : initializer_list<ll>{args...}){
        ret <<= t;
        ret |= v;
    }
    return ret;
}

const ll mod = Num(t,t,t,f,t,t,t,f,f,t,t,f,t,f,t,t,f,f,t,f,t,f,f,f,f,f,f,t,t,t);

ll md(ll x){
    if(x >= mod){
        x -= mod;
    }
    return x;
}

ll mm(ll a, ll b){
    ll ret = f;
    if(a>b){
        swap(a, b);
    }
    while(a){
        if(a&t){
            ret += b;
            ret = md(ret);
        }
        b <<= t;
        a >>= t;
        b = md(b);
    }
    return ret;
}

ll pp(ll a, ll b){
    ll x = a+b;
    if(x >= mod){
        x-=mod;
    }
    return x;
}

struct Mat{
    ll ul, ur,
       dl, dr;
    Mat(){
        ul = ur = dl = dr = f;
    }
    Mat(ll _ul, ll _ur, ll _dl, ll _dr){
        ul = _ul;
        ur = _ur;
        dl = _dl;
        dr = _dr;
    }
    Mat mul(const Mat &m){
        Mat ret;
        ret.ul = pp(mm(ul, m.ul), mm(ur, m.dl));
        ret.ur = pp(mm(ul, m.ur), mm(ur, m.dr));
        ret.dl = pp(mm(dl, m.ul), mm(dr, m.dl));
        ret.dr = pp(mm(dl, m.ur), mm(dr, m.dr));
        return ret;
    }
};

ll R(ll i){
    if(i == f){
        return t+t;
    }
    if(i == t){
        return t;
    }
    Mat ret(t, f, f, t);
    Mat two(t, t, t, f);
    Mat las(t, f, t+t, f);
    ll x = i-t;
    while(x){
        if(x&t){
            ret = ret.mul(two);
        }
        two = two.mul(two);
        x >>= t;
    }
    ret = ret.mul(las);
    return ret.ul;
}

int main(){
    ll C;
    cin >> C;
    for(int i=f; i<C; i++){
        ll N;
        cin >> N;
        cout << R(N) << endl;
    }
    return f;
}
0