【1】做题心得 - 2026 NOICA #14 - T1
观察没观察出来,然后二项式定理又忘了。巨大愤怒生气。
首先我们观察到 \(i\oplus (i-1)\) 的本质就是 \(i-1\to i\) 相差的全部位,那么就是 \(i\) 最后一位的位置,把后面的 \(0\) 全部填上 \(1\),也就是 i&(-i) 取出的 \(x=\text{lowbit}\) 的 \(2x-1\)。那么,对于一个元素,其能贡献的位数就是 \(\log_2(\text{lowbit})\)。对于这个,我们可以发现,从低往高第 \(i\) 位(\(\texttt{1-index}\))为 \(\text{lowbit}\) 的数一共有 \(2^{n-i}\) 个。则我们就可以这样表示两式:
然后我们观察二项式定理:
那么此时我们为了更加方便使用这个式子,可以往 \(a,b\) 内填数,以适应题目中的具体情形。那么,对于这题,我们需要保留 \(2^i\) 项,然后使得 \(b^{n-i}\) 项被隐式使用,那么就能填 \(a=2,b=1\),此时我们求出来的式子就是:
那么我们考虑 \(S_1\) 的式子我们该如何运用:
这个东西打表是可以求出来的,但是我们还要求一个东西就是 \(S_2\)。同理,我们转化一下 \(S_2\) 的意义,类似上方的推导我们可以得出一个式子:
这个东西有系数,很烦。所以我们考虑暴力拆开:
你发现这个东西还是带系数的,这点比较难受,所以我们使用吸收公式来处理这个系数(可能是因为我数学题练的不够多,所以没想到这一点,然后就没推出 \(S_2\) qwq)。
那么把这个东西带入 \(S_2\) 就能得出答案:
时间复杂度 \(\mathcal O(T)\)
::::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;
}
::::
文章同步载入于洛谷,详见文章下方链接。
本文来自博客园,作者:Ivan422,转载请注明原文链接:https://www.cnblogs.com/Exfish/p/23387721。

浙公网安备 33010602011771号