题意:有一张纸,有四种折叠方式,从上到下,下到上,左到右,右到左,给出一个数字n,折叠n次,共有4的n次方种折叠方式,然后横着和竖着在中心线各切一刀,求最后的纸片块数的数学期望。
思路:从上到下,下到上效果相同,左到右,右到左效果相同,故有两种情况。两种情况分别折叠a次和b次,产生2的a次方乘以2的b次方个矩形,再切割,答案为
所以期望值为
最后化简得求
即可。
具体化简过程可参考:
https://www.cnblogs.com/stelayuri/p/13435083.html
注意:求快速幂;求逆元。
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 998244353;
ll n;
ll qPow(ll a,ll b){
ll sum=1;
a%=mod;
while(b)
{
if(b&1)
sum=(sum*a)%mod;
b>>=1;
a=(a*a)%mod;
}
return sum;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int tcase;
cin>>tcase;
while(tcase--){
cin>>n;
ll a1 = qPow(2,n),a2 = qPow(3,n),a3=qPow(a1,mod-2);
cout<<(1+a1+2*a2*a3)%mod<<endl;
}
return 0;
}