关于题意
题意即为求:
其中 指斐波那契数列第 项。
分析
对于分母没有计算难度。
而对于分子,由于 很大,不能暴力,将原式优化:
首先需要了解到 。
证明
用数学归纳法, 时等式成立。
假设 成立。
证明 成立:
左式是 ,右式是 。
左右两式相等,证毕。
矩阵优化即可。
#include<bits/stdc++.h>
using namespace std;
int t,n;
const int N=5,mod=998244353;
struct pio{
long long a[N][N],n,m;
pio(){
memset(a,0,sizeof(a));
}
pio operator *(const pio &b){
int n_=n,m_=b.m,p=m;
pio ans;
ans.n=n_,ans.m=m_;
for(int i=1;i<=n_;i++){
for(int j=1;j<=m_;j++){
for(int k=1;k<=p;k++){
ans.a[i][j]+=1ll*a[i][k]*b.a[k][j]%mod;
ans.a[i][j]%=mod;
}
}
}
return ans;
}
void out(){
cout<<n<<" "<<m<<"\n";
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cout<<a[i][j]<<" ";
}
cout<<"\n";
}
cout<<"\n";
}
};
pio qpow(pio a,int y){
pio ans;
ans.n=ans.m=2;
ans.a[1][1]=ans.a[2][2]=1;
while(y){
if(y&1)ans=ans*a;
y>>=1;
a=a*a;
}
return ans;
}
int QPOW(int a,int y){
int ans=1;
while(y){
if(y&1)ans=1ll*ans*a%mod;
y>>=1;
a=1ll*a*a%mod;
}
return ans;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>t;
while(t--){
cin>>n;
pio te;
te.n=te.m=2,te.a[1][1]=te.a[1][2]=te.a[2][1]=1;
pio tem=qpow(te,n+1);
pio xiang;
xiang.n=1,xiang.m=2,xiang.a[1][1]=xiang.a[1][2]=1;
pio ans=xiang*tem;
int ans1=(1ll*ans.a[1][2]*n%mod-ans.a[1][1]+mod+2)%mod;
cout<<1ll*ans1*QPOW(1ll*n*(n+1)/2%mod,mod-2)%mod<<"\n";
}
return 0;
}