Company: TeraData_6thaug
Difficulty: medium
Binary palindromic numbers A binary palindromic number is a number whose binary representation reads the same forwards and backwards. The binary representation is always written with the minimum number of bits , that is, without any leading zeros. For example 3 is binary palindromic because it is 11 , and 5 is binary palindromic because it is 101 . 4 is not: it is 100 , and 001 reversed is not the same string. Padding is never allowed — 5 is judged as 101 , never as 0101 . You are given a number N . In one operation you may either increase the current value by 1 , or decrease the current value by 1 . Report the minimum number of operations needed to turn N into a binary palindromic number. Input Format The first line contains an integer T , the number of test cases. Each of the next T lines contains a single integer N . Output Format For each test case, print on its own line the minimum number of operations required. Constraints 1 <= T <= 10^5 1 <= N <= 2 x 10^9 Examples Ex