[Python, С++, Java, Scala, Rust] Elegant & Short | O(1) Math
Complexity\n- Time complexity: O(\log_2 {max(n, k}))\n- Space complexity: O(1)\n\n# Code\nPython []\nclass Solution:\n    def minChanges(self, n: int, k: int) -
# Complexity\n- Time complexity: $$O(\\log_2 {max(n, k}))$$\n- Space complexity: $$O(1)$$\n\n# Code\n```Python []\nclass Solution:\n    def minChanges(self, n: int, k: int) -> int:\n        if n & k != k:\n            return -1\n        return (n ^ k).bit_count()\n```\n```C++ []\nclass Solution {\npublic:\n    int minChanges(int n, int k) {\n        if ((n & k) != k)\n            return -1;\n        return std::bitset<32>(n ^ k).count();\n    }\n};\n```\n```Java []\nclass Solution {\n    public int minChanges(int n, int k) {\n        if ((n & k) != k)\n            return -1;\n        return Integer.bitCount(n ^ k);\n    }\n}\n```\n```Scala []\nobject Solution {\n  def minChanges(n: Int, k: Int): Int = {\n    if ((n & k) != k) {\n      -1\n    } else {\n      Integer.bitCount(n ^ k)\n    }\n  }\n}\n```\n```Rust []\nimpl Solution {\n    pub fn min_changes(n: i32, k: i32) -> i32 {\n        if (n & k) != k {\n            return -1;\n        }\n        (n ^ k).count_ones() as _\n    }\n}\n```
['Math', 'Bit Manipulation', 'Python', 'Java', 'Python3']