Counting Pairs
Time limit1sMemory limit2048 MB
Count pairs (i, j) where A_i and A_j never both have a 1 at the same even bit position (bits 0, 2, 4, ...), which is exactly when the base-2 and base-4 results match.
- Level
Medium6 of 10
- Topics
- Bit manipulation, Dynamic programming
- Solved
- No attempts yet
Problem
Consider the binary operator defined for as follows. First, convert both and into base . Then, for each corresponding digit pair, the resulting digit is the sum of the digit pair modulo . Finally, convert the result back to base ten. Note that is the bitwise XOR operator.
For instance, . The base four representations of 18 and 7 are and . Adding each digit pair gives , which is 21 in base ten.
You are given a list of integers, . Count the pairs with such that .
Input
The first line contains an integer (). The second line contains integers ().
Output
Print a single integer, the number of pairs such that and .