规律题,在OEIS查了一下,找到了这个,所以说$f(i) = frac{(2^i - 2^{i-1}) (2 ^ i - 2 ^ {i-2}) ..... (2 ^ i - 2 ^ 0)}{(2 ^ i) ^ i}$
列出:
$f(i) = frac{(2 ^ i - 2 ^ 0) (2 ^ i - 2 ^ 1).......(2^i - 2^{i-1})}{(2 ^ i) ^ i} = frac{(2 ^ {i + 1} - 2 ^ 1) (2 ^ {i + 1} - 2 ^ 2).......(2^{i + 1} - 2^ i)}{(2 ^ i) ^ {i + 1}}$
即$f(i) = frac{(2 ^ {i + 1} - 2 ^ 1) (2 ^ {i + 1} - 2 ^ 2).......(2^{i + 1} - 2^ i)}{(2 ^ {i + 1}) ^ i}$
$f(i + 1) = frac{(2 ^ {i + 1} - 2 ^ 0) (2 ^ {i + 1} - 2 ^ 1)(2 ^ {i + 1} - 2 ^ 2).......(2^{i + 1} - 2^ i)}{(2 ^ {i + 1}) ^ {i + 1}}$
可推出$f(i + 1) = f(i) * frac{2 ^ {i + 1} - 2 ^0 }{2 ^ {i + 1}}$
Code:
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; typedef long long ll; const int N = 2e7 + 10; const int mod = 1e9 + 7; ll qmi(ll a, ll b, ll p){ ll res = 1; while(b){ if(b & 1) res = res * a % p; a = a * a % p; b >>= 1; } return res; } ll ans[N], res[N]; void init(){ res[0] = 1; ll k = 1, infact = 1, mid = qmi(2, mod - 2, mod); for(int i = 1; i <= N - 10; i ++){ k = k * 2 % mod; infact = infact * mid % mod; res[i] = res[i - 1] * (k - 1 + mod) % mod * infact % mod; } ans[1] = res[1]; for(int i = 2; i <= N - 10; i ++){ ans[i] = res[i] ^ ans[i - 1]; } } void solve(){ int n; scanf("%d", &n); printf("%lld ",ans[n]); } int main(){ int t = 1; scanf("%d", &t); init(); while(t --){ solve(); } return 0; }