【1】做题心得 - 2026 NOICA #14 - T1【数学】【二项式定理】【打表】【吸收公式】
观察没观察出来,然后二项式定理又忘了。巨大愤怒生气。
首先我们观察到 i&(-i) 取出的
然后我们观察二项式定理:
那么此时我们为了更加方便使用这个式子,可以往
那么我们考虑
这个东西打表是可以求出来的,但是我们还要求一个东西就是
这个东西有系数,很烦。所以我们考虑暴力拆开:
你发现这个东西还是带系数的,这点比较难受,所以我们使用吸收公式来处理这个系数(可能是因为我数学题练的不够多,所以没想到这一点,然后就没推出
那么把这个东西带入
时间复杂度
::::success[]
#define FileIO
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define il inline
bool stMem; double stT=clock();
const int N=1e5+10;
ll P=998244353;
il ll qp(ll a,ll b=P-2){
ll res=1;
for(;b;b>>=1,a=(a*a)%P) if(b&1) res=(res*a)%P;
return res;
}
// ---------------------------------------------------- //
ll n;
// ---------------------------------------------- ------ //
il void solve(){
cin>>n>>P;
if(P==1){ cout<<"0 0\n"; return; }
ll S1=(qp(3,n)-qp(2,n)+P)%P;
ll S2=(n%P*qp(2,2*n-1)%P-n%P*qp(3,n-1)%P+P)%P;
cout<<S1<<" "<<S2<<"\n";
return;
}
// ---------------------------------------------------- //
bool edMem;
int main(){
#ifdef FileIO
freopen("number.in","r",stdin);
freopen("number.out","w",stdout);
#endif
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int T=1; cin>>T;
while(T--) solve();
cerr<<"\n";
cerr<<"[Info] End Of Running. \n";
cerr<<" Time Used : "<<(clock()-stT)/CLOCKS_PER_SEC*1000.00<<" ms\n";
cerr<<" Memory Used : "<<(&stMem-&edMem)/1048576.00<<" Mib\n";
return 0;
}
::::