XOR Pairs
InterviewTime limit1sMemory limit1024 MB
Count ordered pairs (A, B) where A and B are at most A XOR B, A XOR B is at most N, and A XOR B is not in the set S.
- Level
Medium5 of 10
- Topics
- Bit manipulation, Math, Hash map
- Solved
- No attempts yet
Problem
XOR is a bitwise operator that outputs 1 if and only if the corresponding input bits differ (one of them is 1 while the other is 0). The XOR operator is usually written with the symbol , or with the character ^ (caret) in most programming languages. For example, .
10 => 1010
6 => 0110
----- ⊕
1100 => 12
In this problem, you are given an integer and a set of integers . Count the ordered pairs such that and .
For example, let and . There are 6 pairs that satisfy the condition.
- →
- →
- →
- →
- →
- →
The pair does not satisfy the condition, since and . The pair also fails, because it violates .
Input
The first line contains two integers and (, ). is the given bound, and is the size of the set . The next line contains integers (), the elements of the set.
Output
Print one integer on a line: the number of pairs such that and .