The sixth B-Binary Vector of the 2020 Summer Niuke Multi-school

The
meaning of the question here : Given us n n-dimensional vectors, ask the probability that these n vectors are linearly independent.
Idea:
n=1, there is 0, a two vectors are linearly related to a.
n = 2, there are 0, a, b, a+b four vectors and a, b linearly related
n = 3, there are 0, a, b, c, a+b, a+c, b+c, a+ The eight vectors b+c are
linearly related
to a,, b, and c. From this, when n=i, the probability of irrelevance is 2 i vectors can be correlated with the previous ones, so the current vector must not belong to the previous one. Vector space is fine.
This is the idea given by the official problem solution: in

addition, it can be found by finding the law, because N = 2e7 is very huge, it is not very feasible to directly consider the law of the size of n for each item itself, then we can consider the direct Contact, we can get Fn = Fn-1 * 2 n -1/2 n , so a preprocessing can be solved

Code:

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int MOD = 1e9+7;
const int MAXN = 2e7+7;
const int INV = 5e8+4;

ll f[MAXN];

int main()
{
    
    
	f[1] = INV;
	ll t1 = 2,t2 = INV;
	for(int i = 2;i < MAXN;i ++){
    
    
		t1 = (t1*2)%MOD;
		t2 = t2*INV%MOD;
		f[i] = (f[i-1]*(t1-1)%MOD*t2%MOD)%MOD;
	}
	for(int i = 2;i < MAXN;i ++){
    
    
		f[i] ^= f[i-1];
	}
	int t;
	scanf("%d",&t);
	while(t--){
    
    
		int n;
		scanf("%d",&n);
		printf("%lld\n",f[n]);
	}
	return 0;
}

Guess you like

Origin blog.csdn.net/weixin_45672411/article/details/107661227