Given a number n, the task is to check whether it can be expressed as a sum of two or more consecutive numbers or not.
NOTE: Return "1" if number can be expressed as sum of consecutives else "0". (Without the double quotes)
Example 1:
Input: n = 10
Output: 1 
Explanation: It can be expressed as sum of 
two or more consecutive numbers 1+2+3+4.
Example 2:
Input: n = 16
Output: 0
Explanation: It cannot be expressed as 
sum of two or more consecutive numbers.
Your Task:  
You dont need to read input or print anything. Complete the function canBeSumofConsec() which takes n as input parameter and returns  1 if number can be expressed as sum of consecutives else 0.
Expected Time Complexity: O(1)
Expected Auxiliary Space: O(1)
Constraints:
1<= n <=10^{18}

Source: geeksforgeeks | Difficulty: EASY
Tags: Bit manipulation

Data structures

Mathematics

Starter code: #User function Template for python3

class Solution:

    def canBeSumofConsec (self, n):

        # code here 

Solutions:
class Solution:

	def canBeSumofConsec(self, n):
		if n & n - 1:
			return 1
		return 0


class Solution:

	def canBeSumofConsec(self, n):
		if n % 2 == 1 and n > 1:
			return 1
		elif n == 1:
			return 0
		elif n % 2 == 0:
			while n > 1:
				n = n / 2
				if n % 2 == 1 and n > 1:
					return 1
					break
				if n == 1:
					return 0
					break


class Solution:

	def canBeSumofConsec(self, n):
		return int(bin(n)[2:].count('1') > 1)


import math

class Solution:

	def canBeSumofConsec(self, n):
		c = math.log(n, 2)
		if c == int(c):
			return 0
		else:
			return 1


class Solution:

	def canBeSumofConsec(self, n):
		return int(bool(n and n & n - 1))


class Solution:

	def canBeSumofConsec(self, n):
		c = 1
		for i in range(1, n):
			x = c * 2
			if x <= n:
				c = x
			else:
				break
		if c == n:
			return 0
		return 1


class Solution:

	def canBeSumofConsec(self, n):
		if n & 1:
			return 1
		c = 0
		while n:
			if n & 1:
				c += 1
			n = n >> 1
		if c == 1:
			return 0
		return 1


class Solution:

	def canBeSumofConsec(self, n):
		if (n & n - 1 and n) == n:
			return 1
		else:
			return 0


class Solution:

	def canBeSumofConsec(self, n):
		k = 1
		while 2 * n >= k * (k + 1):
			val = (2 * n - k * (k + 1)) / (2 * (k + 1))
			if int(val) == val:
				return 1
			k += 1
		return 0


class Solution:

	def canBeSumofConsec(self, n):
		j = 2
		while j < n:
			j = j * 2
		if j == n:
			return 0
		return 1


class Solution:

	def canBeSumofConsec(self, n):
		if n & n - 1 and n:
			return 1
		return 0
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		n = int(input())
		ob = Solution()
		print(ob.canBeSumofConsec(n))


class Solution:

	def canBeSumofConsec(self, N):
		n = 2
		while 2 * N - n ** 2 + n > 0:
			a = (2 * N - n ** 2 + n) / (2 * n)
			if a - int(a) == 0:
				return 1
			n += 1
		return 0
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		n = int(input())
		ob = Solution()
		print(ob.canBeSumofConsec(n))


import math

class Solution:

	def canBeSumofConsec(self, n):
		i = int(math.log2(n))
		d = math.log2(n)
		if d - i == 0:
			return 0
		else:
			return 1


import math

class Solution:

	def canBeSumofConsec(self, n):
		x = math.log2(n)
		if math.floor(x) == math.ceil(x):
			return 0
		else:
			return 1


import math

class Solution:

	def canBeSumofConsec(self, n):
		if math.ceil(math.log10(n) / math.log10(2)) == math.floor(math.log10(n) / math.log10(2)):
			return 0
		else:
			return 1


class Solution:

	def canBeSumofConsec(self, n):
		ans = 0
		while n:
			ans += n & 1
			n = n >> 1
		if ans == 1:
			return 0
		else:
			return 1


class Solution:

	def canBeSumofConsec(self, n):
		i = 1
		while pow(2, i) <= n:
			if pow(2, i) == n:
				return 0
			i += 1
		return 1


class Solution:

	def canBeSumofConsec(self, n):
		import math
		if bin(n).count('1') == 1:
			return 0
		else:
			return 1


class Solution:

	def canBeSumofConsec(self, n):
		i = 1
		flag = 1
		while 2 ** i <= n:
			if 2 ** i == n:
				flag = 0
				break
			i += 1
		return flag