D
思路:
首先确定概率值:因为每一个信号塔有信号的可能性是1/2,所以可以确定分母就是2^n;再看分子,其实就是求有多少种可能性,不难发现,如果开一个数组的话,a[1] = 1, a[2] = 1,此后a[n] = a[n-1] + a[n-2],分子即为a[n]
所以概率值为a[n]
再利用逆元进行分数取模,注意在每一个可能溢出的地方取模
代码:
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6+10;
typedef long long LL;
int test=1;
int n;
LL p = 998244353;
LL a[N];
LL inv(LL t)
{
return t==1?1:(p-p/t)*inv(p%t)%p;
}
LL quickpower(LL base, LL power)
{
LL res = 1;
while(power)
{
if(power&1)
{
res = (res * base) % p;
power--;
}
power/=2;
base = base * base % p;
}
return res;
}
int main()
{
a[1] = 1;
a[2] = 1;
for(int i=3;i<=200000;i++)
{
a[i] = (a[i-1] + a[i-2]) % p;
}
//scanf("%d",&test);
while(test--)
{
cin >> n;
cout << ((a[n]%p) * (inv(quickpower(2,n)%p) % p)) % p << '\n';
}
return 0;
}