Given a positive number k, we need to find a minimum value of positive integer n, such that XOR of n and n+1 is equal to k. If no such n exist then print -1.
Example 1:
Input: k = 3
Output: 1
Explaination: 1 xor 2 = 3.
Example 2:
Input: k = 6
Output: -1
Explaination: There is no such n, so that, 
n xor n+1 = k.
Your Task:
You do not need to read input or print anything. Your task is to complete the function xorCal() which takes k as input parameter and returns the value of n. If there is no such , then it returns -1.
Expected Time Complexity: O(1)
Expected Auxiliary Space: O(1)
Constraints:
1 ≤ k ≤ 100

Source: geeksforgeeks | Difficulty: MEDIUM
Tags: Mathematics

Starter code: #User function Template for python3

class Solution:
    def xorCal(self, k):
        # code here

Solutions:
class Solution:

	def xorCal(self, k):
		if k == 1:
			return 2
		if k & k + 1 == 0:
			return k >> 1
		return -1


class Solution:

	def xorCal(self, k):
		if k == 1:
			return 2
		return -1 if k & k + 1 else k // 2


class Solution:

	def xorCal(self, k):
		if k == 1:
			return 2
		for i in range(k):
			if i ^ i + 1 == k:
				return i
		return -1


class Solution:

	def xorCal(self, k):
		p = k + 1
		i = 0
		s = bin(k)[2:]
		l = len(s)
		if k == 0:
			return 0
		if k == 1:
			return 2
		if s.count('1') == l:
			h = '1' * (l - 1)
			return int(h, 2)
		else:
			return -1


class Solution:

	def xorCal(self, k):
		n = 1
		if k == 1:
			return 2
		while n <= k:
			if k ^ n == n + 1:
				return n
			else:
				n += 1
		return -1


from math import log2

class Solution:

	def xorCal(self, k):
		if k & k + 1:
			return -1
		k += 1
		k = int(log2(k))
		k -= 1
		if k == 0:
			return 2
		return int('1' * k, 2)


class Solution:

	def xorCal(self, k):
		if k == 1:
			return 2
		elif k & k + 1 == 0:
			return k // 2
		else:
			return -1


class Solution:

	def xorCal(self, k):
		for i in range(1, 100):
			if i.__xor__(i + 1) == k:
				return i
		return -1


class Solution:

	def xorCal(self, k):
		map = {1: 2, 3: 1, 7: 3, 15: 7, 31: 15, 63: 31}
		if k not in map:
			return -1
		return map[k]
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		k = int(input())
		ob = Solution()
		print(ob.xorCal(k))


class Solution:

	def xorCal(self, k):
		if k == 1:
			return 2
		if k + 1 & k == 0:
			return k // 2
		return -1
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		k = int(input())
		ob = Solution()
		print(ob.xorCal(k))


class Solution:

	def xorCal(self, k):
		n = n1 = k
		n = n >> 1
		n1 = n1 << 1
		if n != 0 and n ^ n + 1 == k:
			return n
		if n1 ^ n1 + 1 == k:
			return n1
		return -1


class Solution:

	def xorCal(self, k):
		i = 1
		while i <= 105:
			if i ^ i + 1 == k:
				return i
			i += 1
		return -1


class Solution:

	def xorCal(self, k):
		if k == 1:
			return 2
		i = 1
		while pow(2, i) <= k:
			a = pow(2, i)
			if k == a + (a - 1):
				return a - 1
			i += 1
		return -1


class Solution:

	def xorCal(self, k):
		if k == 1:
			return 2
		l = [1, 3, 7, 15, 31, 63]
		if k in l:
			return int(k / 2)
		return -1


class Solution:

	def xorCal(self, k):
		a = []
		for i in range(1, 100):
			a = i
			b = i + 1
			if a ^ b == k:
				return a
		return -1


class Solution:

	def xorCal(self, k):
		for n in range(1, 100):
			if n ^ n + 1 == k:
				return n
		return -1


class Solution:

	def xorCal(self, k):
		if k == 1:
			return 2
		string = bin(k)
		li = list(string[2:])
		if len(set(li)) == 1:
			return k // 2
		else:
			return -1


class Solution:

	def xorCal(self, k):
		a = {1: 2, 3: 1, 7: 3, 15: 7, 31: 15, 63: 31}
		if k in a:
			return a[k]
		else:
			return -1


class Solution:

	def xorCal(self, K):
		for i in range(1, 7 * K):
			if i ^ i + 1 == K:
				return i
		return -1


class Solution:

	def xorCal(self, k):
		if k == 1:
			return 2
		a = bin(k)[2:]
		b = len(a)
		c = 2 ** b
		if c - 1 == k:
			return 2 ** (b - 1) - 1
		return -1


class Solution:

	def xorCal(self, k):
		if k == 1:
			return 2
		i = 1
		while i < k:
			if k == i ^ i + 1:
				return i
				break
			i += 1
		return -1


class Solution:

	def xorCal(self, k):
		checkxor = 0
		numxor = 0
		index = 1
		for index in range(1, 129):
			if index ^ k == index + 1:
				checkxor = 1
				numxor = index
				break
			index += 1
		if checkxor == 1:
			return numxor
		else:
			return -1


import math

class Solution:

	def xorCal(self, k):
		if k == 1:
			return 2
		temp = math.log(k + 1, 2)
		if temp != int(temp):
			return -1
		else:
			return k // 2


class Solution:

	def xorCal(self, k):
		i = 1
		while i + 1 <= 100000:
			if i ^ i + 1 == k:
				return i
			i = i + 1
		return -1


class Solution:

	def xorCal(self, k):
		if k == 0:
			return 0
		if k == 1:
			return 2
		if k == 3:
			return 1
		n = k + 1
		if n & n - 1 == 0:
			return k // 2
		else:
			return -1


class Solution:

	def xorCal(self, k):
		k2 = int(k / 2)
		if k == 1:
			return 2
		if k % 2 == 0:
			return -1
		if k2 ^ k2 + 1 == k:
			return k2
		else:
			return -1


class Solution:

	def xorCal(self, k):
		n = 1
		result = False
		while n < 100:
			temp = n ^ n + 1
			if k == temp:
				result = True
				break
			else:
				n += 1
		else:
			return -1
		return n


class Solution:

	def xorCal(self, k):
		for i in range(1, 101):
			if i ^ i + 1 == k:
				return i
				break
		return -1


class Solution:

	def xorCal(self, k):
		if k % 2 == 0:
			ans = -1
		elif k == 1:
			ans = 2
		elif k == 3:
			ans = 1
		elif k == 7:
			ans = 3
		elif k == 15:
			ans = 7
		elif k == 31:
			ans = 15
		elif k == 63:
			ans = 31
		else:
			ans = -1
		return ans