Number of Distinct Integers in Base-3

90 Views Asked by At

Given:

  • An integer $A$ and a natural number $K$.

  • XOR operation in base-3 on bits $x \ and \ y$ is defined as follows, $$ x\newcommand*\xor{\mathbin{\oplus}}y=1,⇔ x=y \\x\newcommand*\xor{\mathbin{\oplus}}y=0, ⇔ x ≠y$$

To find: Number of distinct integers $B$ in base-3 subjected to following conditions:

  • No of bits in number base-3 representation of $A$ and $B$ are same.
  • No of $0$ bits in resultant XOR of $A$ and $B$ in base-3 <= $K$

  • The number base-3 representation of $B = b_{n-1}b_{n-2}....b_1b_0$ doesn't contain any triplets $(i,j,k)$ such that

    1. $2*j = i+k$
    2. $b_i=b_j=b_k$