推导
当然,我们从小部分来推导。 :暴力找循环节。 :暴力找循环节,打表。或你已经看出规律,用光速幂超时了。 :你通过打表发现了规律:除了 以外,所有的解都是 !然后你写了光速幂,如果被卡到 ,尝试减少取模次数。
AC Code
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int p=998244353;
int T;
inline ll mul(ll x,ll y){
ll res=0;
while(y){
if(y&1)res=(res+x);
x=x+x;
y>>=1;
}
return res;
}
inline ll qpow(ll x,ll y){
ll res=1;
while(y){
if(y&1)res=mul(res,x)%p;
x=mul(x,x)%p;
y>>=1;
}
return res%p;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cin>>T;
while(T--){
ll n;
cin>>n;
if(n==1)cout<<"NO\n";
else{
ll ans=(qpow(2,n)-1+p)%p;
cout<<ans<<'\n';
}
}
return 0;
}