Conjunctive Sequences
A sequence (x_1, x_2,..., x_n) of non-negative integers is called conjunctive if for every consecutive pair, x_i mathbin& x_(i+1) ne 0 (where & denotes bitwise AND). Let c(n, b) denote the number o...
Problem Statement
This archive keeps the full statement, math, and original media on the page.
Let ’\(\& \)’ denote the bitwise AND operation. For example, \(10\,\& \, 12 = 1010_2\,\& \, 1100_2 = 1000_2 = 8\).
We shall call a finite sequence of non-negative integers \((a_1, a_2, \ldots , a_n)\)
Define \(c(n,b)\) to be the number of conjunctive sequences of length \(n\) in which all terms are \(\le b\).
You are given that \(c(3,4)=18\), \(c(10,6)=2496120\), and \(c(100,200) \equiv 268159379 \pmod {998244353}\).
Find \(c(123,123456789)\). Give your answer modulo \(998244353\).
Problem 774: Conjunctive Sequences
Mathematical Foundation
Definition. Let be the number of bits needed to represent integers up to . For a non-negative integer , define its bit-set .
Lemma 1 (AND Condition via Bit-sets). if and only if .
Proof. has a in bit position iff both and have a in position . So iff some bit position is shared, i.e., .
Definition. For a subset , define — the count of integers up to that have all bits in set.
Lemma 2 (Inclusion-Exclusion for Compatible Counts). For a given with , the number of integers with is
Proof. By inclusion-exclusion on the events “bit of is set” for :
Theorem 1 (Subset-based Transfer Matrix). Define for each non-empty subset the count . The number of conjunctive sequences of length is
This is equivalent to computing the -th power of a transfer matrix indexed by non-empty subsets of , where .
Proof. Each term with contributes choices. The conjunctive condition is equivalent to by Lemma 1. The matrix product formulation follows from the standard transfer matrix method.
Theorem 2 (Mobius Inversion on the Boolean Lattice). The transfer matrix can be diagonalized using the Mobius function of the Boolean lattice (i.e., the zeta/Mobius transforms). Specifically, , so
where for all and . The matrix factors over bits: where if or , i.e., . This tensor product structure enables efficient computation via subset convolution and the “sum over supersets” (SOS) transform.
Proof. iff for every bit , at least one of does not contain . This gives the product decomposition. The SOS transform diagonalizes each factor, reducing the matrix power to pointwise exponentiation in the transform domain.
Lemma 3 (Efficient Computation via Ranked Mobius Transform). Using the ranked Mobius transform (subset convolution), the matrix power applied to the initial vector can be computed in time per step and matrix power steps (via polynomial multiplication in the rank variable), giving total time with repeated squaring.
Proof. The subset convolution framework of Bjorklund et al. (2007) allows computing the “OR-convolution restricted to disjoint sets” in time. The transfer matrix multiplication in the transform domain becomes pointwise polynomial multiplication (polynomials in the rank variable of degree at most ). Matrix exponentiation via repeated squaring requires multiplications.
Editorial
Sequence of non-negative integers where consecutive terms have nonzero bitwise AND. = count of length- sequences with terms . Find . We compute alpha(S) for all non-empty S via digit DP. We then alpha(S) = count of x in [0, b] with bits(x) = S. Finally, where w(T) = floor(b / 2^{bits in T positions}) … (digit DP for upper bound).
Pseudocode
Compute alpha(S) for all non-empty S via digit DP
alpha(S) = count of x in [0, b] with bits(x) = S
Use inclusion-exclusion: alpha(S) = sum_{T supseteq S} (-1)^{|T|-|S|} w(T)
where w(T) = floor(b / 2^{bits in T positions}) ... (digit DP for upper bound)
Actually, compute w(T) = |{x <= b : T subseteq bits(x)}| via digit DP
Then Mobius invert: alpha(S) = sum_{T supseteq S} (-1)^{|T\S|} w(T)
Set up the transfer matrix in subset convolution domain
Transform alpha into the ranked Mobius domain
f_hat[S][rank] = ranked zeta transform of alpha
Compute the n-th power
In the transform domain, perform pointwise polynomial exponentiation
Each point has a polynomial of degree <= B, raise to power (n-1)
Use matrix exponentiation or polynomial repeated squaring
Inverse transform to get c(n, b)
Sum over all S of the result vector
Detailed subset convolution approach:
Ranked zeta transform
In transform domain: g_hat[S] = polynomial, raise to power n-1
Then multiply by f_hat to get the convolution
This requires O(2^B * B^2 * log(n)) operations
Count x in [0, b] such that T is a subset of bits(x)
Standard digit DP on the binary representation of b
Complexity Analysis
- Time: where (since ). This gives approximately , which is tight but feasible with constant-factor optimizations. Alternatively, an eigenvalue-based approach exploiting the symmetric structure reduces this further.
- Space: bits MB, which is tight. Optimizations (e.g., working in compressed representations) may be needed.
Answer
Code
Each problem page includes the exact C++ and Python source files from the local archive.
#include <bits/stdc++.h>
using namespace std;
/*
* Problem 774: Conjunctive Sequences
*
* Sequence of non-negative integers where consecutive terms have nonzero bitwise AND. $c(n,b)$ = count of length-$n$ sequences with terms $\le b$. Find
*/
int main() { printf("Problem 774: Conjunctive Sequences\n"); return 0; }
"""
Problem 774: Conjunctive Sequences
Sequence of non-negative integers where consecutive terms have nonzero bitwise AND. $c(n,b)$ = count of length-$n$ sequences with terms $\le b$. Find $c(123, 123456789) \bmod 998244353$.
"""
print("Problem 774: Conjunctive Sequences")