# 数论 + 概率论 - Paperfolding - HDU 6822

## 2020 Multi-University Training Contest 5

T 组 测 试 数 据 ， T组测试数据，

Sample Input

2
0
1


Sample Output

4
6


1 ≤ T ≤ 1 0 5 ， 0 ≤ n ≤ 1 0 18 1≤T≤10^5，0≤n≤10^{18}

E ( X ) = ∑ i = 0 n P ( X i ) ⋅ X i = 1 2 n ∑ i = 0 n C n i × ( 2 i + 1 ) ( 2 n − i + 1 ) = 1 2 n ∑ i = 0 n C n i ( 2 n + 2 i + 2 n − i + 1 ) E(X)=\sum_{i=0}^nP(X_i)·X_i=\frac{1}{2^n}\sum_{i=0}^nC_n^i×(2^i+1)(2^{n-i}+1)=\frac{1}{2^n}\sum_{i=0}^nC_n^i(2^n+2^i+2^{n-i}+1)

∑ i = 0 n C n i x i = ∑ i = 0 n C n i x i ⋅ 1 n − i = ( 1 + x ) n \sum_{i=0}^nC_n^ix^i=\sum_{i=0}^nC_n^ix^i·1^{n-i}=(1+x)^n

1 2 n ∑ i = 0 n C n i ( 2 n + 2 i + 2 n − i + 1 ) = 1 2 n ( 4 n + 3 n + 2 n ( 1 + 1 2 ) n + 2 n ) \frac{1}{2^n}\sum_{i=0}^nC_n^i(2^n+2^i+2^{n-i}+1)=\frac{1}{2^n}(4^n+3^n+2^n(1+\frac{1}{2})^n+2^n)

#include<cstring>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>

#define ll long long

using namespace std;

const int mod=998244353;

int T;
ll n;

ll quick_pow(ll a,ll b,int mod)
{
ll res=1;
b%=(mod-1);
while(b)
{
if(b&1) res=res*a%mod;
a=a*a%mod;
b>>=1;
}
return res;
}

int main()
{
cin>>T;
ll INV_2=quick_pow(2,mod-2,mod);
while(T--)
{
scanf("%lld",&n);
ll pow_2n=quick_pow(2,n,mod);
ll pow_3n=quick_pow(3,n,mod);
ll INV_p2=quick_pow(pow_2n,mod-2,mod);

ll res=(pow_2n+1)*pow_2n%mod;
res=(res+pow_3n)%mod;
ll tmp=quick_pow(1+INV_2,n,mod)*pow_2n%mod;
res=(res+tmp)%mod*INV_p2%mod;
printf("%lld\n",res);
}

return 0;
}

07-13 1万+

01-25 6880