Official algorithmic problem description and constraints.
The binary parity of an integer N is defined as follows: First, write N in binary. For example, = 13 N=13 is written as 1101 1101 in binary, and = 5 N=5 is written as 101 101. Compute S N β , the sum of the binary digits of N. For example, from the earlier examples, 13 = 1 + 1 + 0 + 1 = 3 S 13 β =1+1+0+1=3 and 5 = 1 + 0 + 1 = 2 S 5 β =1+0+1=2. The binary parity of N is then the parity β β of S N β . 13 = 3 S 13 β =3 is odd, so 13 13 is said to have odd binary parity; while 6 = 2 S 6 β =2 is even, so 5 5 has even binary parity. Given an integer N, find its binary parity. β β The parity of an integer is, quite simply, whether it's even or odd. We say an integer has even parity if it is a multiple of 2 2, and odd parity otherwise.
Detailed video explanations, mathematical intuition, and clean C++ implementation code.