結果

問題 No.3495 2変数半二項展開
コンテスト
ユーザー askr58
提出日時 2026-04-03 23:21:59
言語 C++23
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
RE  
実行時間 -
コード長 1,135 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,722 ms
コンパイル使用メモリ 343,848 KB
実行使用メモリ 7,976 KB
最終ジャッジ日時 2026-04-03 23:22:19
合計ジャッジ時間 5,794 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 7 RE * 13
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#include <atcoder/modint>
using mint=atcoder::modint;
#include <atcoder/math>

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int ttt;
	cin>>ttt;
	while(ttt--){
		ll n,m,l,b;
		cin>>n>>m>>l>>b;
		ll x=m%b,y=l%b;
		vector<vector<ll>> a(4,vector<ll>(4));
		a[0][1]=(2*y)%b;
		a[0][2]=(x-y+b)%b;
		a[1][0]=2%b;
		a[1][3]=(x-y+b)%b;
		a[2][0]=1%b;
		a[3][1]=1%b;
		vector<vector<ll>> res(4,vector<ll>(4));
		for(int i=0;i<4;i++)res[i][i]=1%b;
		ll N=n;
		while(N>0){
			if(N&1){
				vector<vector<ll>> nres(4,vector<ll>(4));
				for(int i=0;i<4;i++)for(int j=0;j<4;j++)for(int k=0;k<4;k++){
					nres[i][j]=(nres[i][j]+a[i][k]*res[k][j])%b;
				}
				res=move(nres);
			}
			vector<vector<ll>> na(4,vector<ll>(4));
			for(int i=0;i<4;i++)for(int j=0;j<4;j++)for(int k=0;k<4;k++){
				na[i][j]=(na[i][j]+a[i][k]*a[k][j])%b;
			}
			a=move(na);
			N>>=1;
		}
		ll p=(2*res[2][1]+2*res[2][2])%b,q=(2*res[3][1]+2*res[3][2])%b;
		//cout<<p.val()<<" "<<q.val()<<endl;
		ll t=atcoder::inv_mod(2,b);
		if(n%2==0)cout<<p*t%b<<endl;
		else cout<<q*t%b<<endl;
	}
}
			
0