結果

問題 No.2816 At Most Two Moves
ユーザー zeta7532
提出日時 2024-07-18 01:16:17
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 28 ms / 2,000 ms
コード長 1,591 bytes
コンパイル時間 2,014 ms
コンパイル使用メモリ 200,316 KB
最終ジャッジ日時 2025-02-23 16:07:42
ジャッジサーバーID
(参考情報)
judge5 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
using ll = __int128;
const ll mod = 998244353;
#define fi first
#define se second
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(x) x.begin(),x.end()
#define faster ios::sync_with_stdio(false);cin.tie(nullptr)

ostream &operator<<(ostream &dest,ll value){
    ostream::sentry s(dest);
    if(s){
        ll tmp=value;
        if(value<0) tmp=-value;
        char buffer[128];
        char *d=end(buffer);
        do{
            --d;
            *d="0123456789"[tmp%10];
            tmp/=10;
        }while(tmp!=0);
        if(value<0){
            --d;
            *d='-';
        }
        int len=end(buffer)-d;
        if(dest.rdbuf()->sputn(d,len)!=len){
            dest.setstate(ios_base::badbit);
        }
    }
    return dest;
}

ll parse(string s){
    ll ret=0;
    rep(i,s.size()){
        ret=ret*10+s[i]-'0';
    }
    return ret;
}

ll c_in(){
    string s;
    cin >> s;
    return parse(s);
}

ll modpow(ll A,ll N){
    ll res=1;
    while(N){
        if(N&1) res=res*A%mod;
        A=A*A%mod;
        N>>=1;
    }
    return res;
}

ll modinv(ll A){return modpow(A,mod-2);}

ll solve(ll N){
    ll ans=0;
    ll M=N%(mod-1)+(mod-1);
    ans+=modpow(2,(M*(M-1))/2);
    ll cnt=(modpow(2,2*M-3)+mod-modpow(3,M-2))*modpow(2,(M*(M-1))/2+(mod-1)*5-(2*M-3));
    cnt%=mod;
    ans+=cnt*(N-1);
    return ans%mod;
}

int main() {
    ll T=c_in();
    while(T--){
        ll N=c_in();
        cout << solve(N) << endl;
    }
    return 0;
}
0