D. 站军姿

参考:随机在圆上生成n个点,这n个点在同一半圆的概率是多少?

思路:直接利用公式,随机在圆上生成n个点,这n个点在同一半圆的概率是\(\frac{n}{2^{n-1}}\) ,求逆元的时候直接用费马小定理即可

代码:

// Created by CAD on 2019/9/8.
#include <bits/stdc++.h>

#define ll long long
using namespace std;
const int mod=1e9+7;
ll qpow(ll x,ll n)
{
    ll re=1;
    while(n>0)
    {
        if(n&1) re=(re*x)%mod;
        n>>=1;
        x=(x*x)%mod;
    }
    return re;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin>>t;
    while(t--)
    {
        ll n;
        cin>>n;
        ll mu=qpow(2,n-1);
        n%=mod;
        ll x=__gcd(mu,n);
        n/=x,mu/=x;
        cout<<n*qpow(mu,mod-2)%mod<<endl;
    }
    return 0;
}