Skip to main content
1 of 3
Achim Krause
  • 10.8k
  • 1
  • 43
  • 51

If you interpret the bit mask as encoding a finite set $S = \{2^{b_i}\}$ of powers of $2$, you are precisely asking whether there exists a subset of $S$ which sums to $A$ modulo $p$. This is known as the modular subset-sum problem, and apparently there are efficient algorithms for it, for example https://arxiv.org/pdf/2008.10577.pdf

Achim Krause
  • 10.8k
  • 1
  • 43
  • 51