Company: Sprinkler_20thjuly
Difficulty: medium
Binary Palindromic Numbers For each given positive integer N , find the minimum number of operations needed to change it into a positive integer whose usual binary representation is a palindrome. One operation changes the current number by exactly one: either increase it by 1 or decrease it by 1 . The value must remain positive after every operation. Binary representations use no leading zeroes. Input Format The first line contains an integer T , the number of test cases. Each of the next T lines contains one integer N . Output Format For every test case, print the minimum required number of operations on its own line. Constraints 1 <= T <= 2000 1 <= N <= 2 * 10^9 Examples Example 1 Input: 3 2 3 4 Output: 1 0 1 2 is 10 in binary, so changing it to 3 ( 11 ) takes one operation. 3 is already a binary palindrome. For 4 ( 100 ), either 3 ( 11 ) or 5 ( 101 ) is one operation away. Notes A binary palindrome reads the same from left to right and from right to left. 0 is not a vali