题解:P12046 [USTCPC 2025] 生成树!
这都啥啊?
首先选出一些与
直接设
T qpow(T x,ll y){
T ret{};repn(i,8)ret[i][i]=1;
while(y){
if(y&1)ret=ret*x;
x=x*x,y>>=1;
}
return ret;
}
signed main(){
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin>>n>>k;
T A{};
repn(i,8){
A[i][i]=1;
if((i&4)&&!(i&1))A[i][i|1]=1;
if(!(i&4)&&!(i&2))A[i][i|2]=1;
}
A=qpow(A,k);
T B{};
repn(i,8){
B[i][i]=1;
if((i&4)&&(i&1))B[i][i^1]=1;
if(!(i&4))B[i][i|4]=1;
}
T r=qpow(A*B,n/k);
cout<<(r[0][5]+r[0][6]).val()<<'\n';
}