loj6358. Eve

The meaning of problems

Set \ (X-= \ {. 1, 2, \ DOTS, n-\} \) , \ (S = 2 ^ X-\) , find the \ (S \) Remove a collection of (time to take), which is the intersection of 4 multiple of the number of programs.
\ (n-\ Leq ^ {10}. 7 \) .

answer

+ Good structure generalized inclusion and exclusion problems.
Set \ (g (x) \) represents the set number of intersection taken exactly \ (X \) is the number of programs, \ (F (X) \) represents Imperial \ (X \) number of programs set must be taken.
Obviously, \ (f (x) = \ Binom {n-} {X} (2 ^ {2 ^ {n-- X}} -. 1) \) , then \ (g (x) \) and \ (f (x ) \) relationship can be determined using the binomial inversion, i.e.
\ [g (k) = \ sum_ {i = k} ^ n {(-1)} ^ {i - k} \ binom {i} { k} f (i) \]
but all binomial inversion request \ (g (x) \) to \ (O (n ^ 2) \) complexity.
Consider an ingenious construction.
Set \ (Ans = \ sum_ {I} = 0 ^ NF (I) A (I) \) .
Since apparently \ (Ans = \ sum_ {I} = 0 ^ ng (I) B (I) \) , where \ (B (I) = [. 4 | I] \) .
then
\ [\ Begin {aligned} Ans & = \ sum_ {k = 0} ^ n [4 | k] \ sum_ {i = k} ^ n {(-1)} ^ {i - k} \ binom {i} {k} f (i) \\ & = \ sum_ {i = 0} ^ nf (i) \ sum_ {k = 0} ^ i {(-1)} ^ {i - k} \ binom {i} { k} [4 | k] \\
\ end {aligned} \] is derived
\ [a (i) = \ sum_ {k = 0} ^ i {(-1)} ^ {i - k} \ binom { i} {k} [4 |
k] \\ \] , but not enough to continue.
For \ ([. 4 | K] \) , root inversion units, i.e.,
\ [[4 | k] = \ frac {1} {4} \ sum_ {i = 0} ^ 3 \ omega_4 ^ {ik} \ ]
then
\ [\ Begin {aligned} a (i) & = \ sum_ {k = 0} ^ i {(-1)} ^ {i - k} \ binom {i} {k} \ frac {1} {4} \ sum_ {l = 0} ^ 3 \ omega_4 ^ {lk} \\ & = \ frac {{(- 1)} ^ i} {4} \ sum_ {k = 0} ^ i {(-1)} ^ k \ binom {i} {k } \ sum_ {l = 0} ^ 3 ({\ omega_4 ^ l}) ^ k \\ & = \ frac {{(- 1)} ^ i} {4} \ sum_ { l = 0} ^ 3 \ sum_ {k = 0} ^ i \ binom {i} {k} {(-1)} ^ k ({\ omega_4 ^ l}) ^ k \\ & = \ frac {{( -1)} ^ i} {4
} \ sum_ {l = 0} ^ 3 (1 - {\ omega_4 ^ l}) ^ i \\ \ end {aligned} \] then this thing is relatively easy.
Direct Calculation
\ [Ans = 1 + \ sum_ {i = 0} ^ n \ binom {n} {i} (2 ^ {2 ^ {n - i}} - 1) \ cdot \ frac {{(- 1) } ^ i} {4} \
sum_ {l = 0} ^ 3 (1 - {\ omega_4 ^ l}) ^ i \] this is a collection of all the programs are not selected (it is noted that \ (f (0 ) \) was removed).
Process, you can use some tricks to avoid the use of fast power.
So this complexity is \ (\ mathcal O (n) \) , the constant of 4 (actually certainly much larger than this).

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int power (int a, int b, int mod) {
    int ret = 1;
    for ( ; b; b >>= 1, a = 1ll * a * a % mod) {
        if (b & 1) {
            ret = 1ll * ret * a % mod;
        }
    }
    return ret;
}

const int N = 1e7 + 3, mod = 998244353;
const int omega = 911660635, inv4 = 748683265;
int n, ans, f, a, w, r[4], s[4];
int fac[N], ivf[N], po[N], pw[N], pn[N];
int C (int p, int q) {
    return 1ll * fac[p] * ivf[q] % mod * ivf[p - q] % mod;
}
void prework () {
    fac[0] = ivf[0] = 1;
    for (int i = 1; i < N; ++i) {
        fac[i] = 1ll * fac[i - 1] * i % mod;
    }
    ivf[N - 1] = power(fac[N - 1], mod - 2, mod);
    for (int i = N - 2; i; --i) {
        ivf[i] = 1ll * ivf[i + 1] * (i + 1) % mod;
    }
    po[0] = 2;
    for (int i = 1; i < N; ++i) {
        po[i] = 1ll * po[i - 1] * po[i - 1] % mod;
    }
    w = 1;
    for (int i = 0; i < 4; ++i) {
        r[i] = (1 - w + mod) % mod;
        s[i] = 1;
        w = 1ll * w * omega % mod;
    }
}
int main () {
    prework();
    cin >> n;
    for (int i = 0; i <= n; ++i) {
        f = 1ll * C(n, i) * (po[n - i] - 1 + mod) % mod;
        a = 0;
        for (int k = 0; k < 4; ++k) {
            a = (a + s[k]) % mod;
            s[k] = 1ll * s[k] * r[k] % mod;
        }
        a = 1ll * a * inv4 % mod;
        a = i & 1 ? mod - a : a;
        ans = (1ll * f * a + ans) % mod;
    }
    cout << (ans + 1) % mod << endl;
    return 0;
}

Guess you like

Origin www.cnblogs.com/psimonw/p/11456746.html