Tap here to switch tabs
Problem
Submissions

Problem: Number of Bit Changes to Make Two Integers Equal

Try to solve the Number of Bit Changes to Make Two Integers Equal problem.

Statement

You are given two positive integers n and k.

In a single operation, you can choose any bit in the binary representation of n that is equal to 11 and change it to 00.

Return the number of operations needed to make n equal to k. If it is impossible to make n equal to k, return −1-1.

Constraints:

  • 1≤1 \leq n, k ≤106\leq 10^6

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Number of Bit Changes to Make Two Integers Equal

Try to solve the Number of Bit Changes to Make Two Integers Equal problem.

Statement

You are given two positive integers n and k.

In a single operation, you can choose any bit in the binary representation of n that is equal to 11 and change it to 00.

Return the number of operations needed to make n equal to k. If it is impossible to make n equal to k, return −1-1.

Constraints:

  • 1≤1 \leq n, k ≤106\leq 10^6