All problems

Problem 242

Hamming Distance

Easy · 10 pts · Bit Manipulation

Problem

The Hamming distance between two non-negative integers is the number of bit positions at which their binary representations differ, after padding the shorter one with leading zeros. Given X and Y, print their Hamming distance. X XOR Y has a 1 exactly in the positions where X and Y differ, so the answer is the number of set bits in X XOR Y. The numbers can be as large as 2^60 - 1 (about 1.15 × 10^18), so use 64-bit integers.

Input

Two integers X and Y.

Output

Print the Hamming distance.

Constraints

0 <= X, Y < 2^60

Example input

1 4

Example output

2

Explanation

1 is 001 in binary and 4 is 100. They differ in the first and the last position, so the Hamming distance is 2. Equivalently, 1 XOR 4 = 101, which has two 1 bits.

Every problem here can be used in a RelayTrixCode team match. Create a room.

Previous: Count Primes in a Range Next: Assign Cookies