D. Radio Towers
手算前7项 1/2,1/4,2/8,3/16,5/32,8/64…
分子斐波那契,分母2^n
1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 const int maxn=2e5+10; 5 const int mod=998244353; 6 ll base[maxn]; 7 void init() 8 { 9 base[1]=1; 10 base[2]=1; 11 for(int i=3;i<=maxn-10;i++){ 12 base[i]=(base[i-1]+base[i-2])%mod; 13 } 14 } 15 ll quick(ll a,ll b) 16 { 17 ll ans=1; 18 while(b>0){ 19 if(b%2!=0) ans=ans*a%mod; 20 a=a*a%mod; 21 b=b/2; 22 } 23 return ans; 24 } 25 void ex_gcd(ll a, ll b, ll &x, ll &y, ll &d){ 26 if (!b) {d = a, x = 1, y = 0;} 27 else{ 28 ex_gcd(b, a % b, y, x, d); 29 y -= x * (a / b); 30 } 31 } 32 ll inv(ll t, ll p){//如果不存在,返回-1 33 ll d, x, y; 34 ex_gcd(t, p, x, y, d); 35 return d == 1 ? (x % p + p) % p : -1; 36 } 37 //int main(){ 38 // LL a, p; 39 // while(~scanf("%lld%lld", &a, &p)){ 40 // printf("%lld\n", inv(a, p)); 41 // } 42 //} 43 int main() 44 { 45 init(); 46 ll n; 47 scanf("%lld",&n); 48 ll tmp=quick(2,n); 49 // printf("%lld\n",tmp); 50 ll ans=base[n]*inv(tmp,mod)%mod; 51 printf("%lld\n",ans); 52 return 0; 53 }