Given a number N.Check whether it is a triangular number or not.
Note: A number is termed as a triangular number if we can represent it in the form of a triangular grid of points such that the points form an equilateral triangle and each row contains as many points as the row number, i.e., the first row has one point, the second row has two points, the third row has three points and so on.
The starting triangular numbers are 1, 3 (1+2), 6 (1+2+3), 10 (1+2+3+4).
Example 1:
Input:
N=55
Output:
1
Explanation:
55 is a triangular number.
It can be represented in 10 rows.
Example 2:
Input:
N=56
Output:
0
Explanation:
56 is not a triangular number.
Your Task:
You don't need to read input or print anything. Your task is to complete the function isTriangular() that takes a number N as input parameter and returns 1 if it is a triangular number. Otherwise, it returns 0.
Expected Time complexity:O(LogN)
Expected Auxillary Space:O(1)
 
Constraints:
1<=N<=10^{6}

Difficulty: EASY
Tags: Mathematics
Expected Time Complexity: O(LogN)
Expected Auxiliary Space: O(1)

Starter code:
#User function Template for python3

class Solution:
    def isTriangular(self, N):
        #code here

Solutions:
class Solution:

	def isTriangular(self, n):
		c = 0
		t = 1
		while c < n:
			c += t
			t += 1
		if c == n:
			return 1
		return 0


class Solution:

	def isTriangular(self, N):
		for i in range(N + 1):
			if N == i * (i + 1) // 2:
				return 1
				break
		return 0


import math

class Solution:

	def isTriangular(self, N):
		for i in range(1, N + 1):
			if i * (i + 1) // 2 == N:
				return 1
		return 0


class Solution:

	def isTriangular(self, N):
		set = {}
		k = 0
		while k <= N and N > 0:
			k += 1
			N = N - k
		if N == 0:
			return 1
		return 0


class Solution:

	def isTriangular(self, N):
		sum = 0
		i = 1
		check = 0
		while sum <= N:
			sum = int(i * (i + 1) / 2)
			i = i + 1
			if sum == N:
				check = 1
				return 1
		if check == 0:
			return 0


class Solution:

	def isTriangular(self, N):
		(num, den) = (-1 + (1 + 8 * N) ** 0.5, 2)
		if num / den == int(num / den):
			return 1
		return 0


class Solution:

	def isTriangular(self, N):
		x = 8.0 * N + 1.0
		if x % x ** 0.5 == 0.0:
			return 1
		else:
			return 0


class Solution:

	def isTriangular(self, N):
		import math
		i = math.floor(math.sqrt(2 * N))
		if i * (i + 1) // 2 == N:
			return 1
		return 0


import math

class Solution:

	def isTriangular(self, N):
		k = int(math.sqrt(2 * N))
		if k * (k + 1) / 2 == N:
			return 1
		return 0


import math

class Solution:

	def isTriangular(self, nums):
		if nums < 0:
			return 0
		c = -2 * nums
		(b, a) = (1, 1)
		d = b * b - 4 * a * c
		if d < 0:
			return 0
		root1 = (-b + math.sqrt(d)) / 2 * a
		root2 = (-b - math.sqrt(d)) / 2 * a
		if root1 > 0 and math.floor(root1) == root1:
			return 1
		if root2 > 0 and math.floor(root2) == root2:
			return 1
		return 0


import math

class Solution:

	def isTriangular(self, N):
		ch = math.ceil(math.sqrt(1 + 8 * N))
		c = math.sqrt(1 + 8 * N)
		if c == ch:
			return 1
		else:
			return 0


class Solution:

	def isTriangular(self, n):
		import math as mt
		i = mt.floor(mt.sqrt(2 * n))
		if i * (i + 1) // 2 == n:
			return 1
		return 0


import math

class Solution:

	def isTriangular(self, n):
		i = math.floor(math.sqrt(2 * n))
		if i * (i + 1) // 2 == n:
			return 1
		else:
			return 0


class Solution:

	def isTriangular(self, N):
		a = int(math.sqrt(2 * N))
		return 1 if a * (a + 1) == 2 * N else 0


class Solution:

	def isTriangular(self, N):
		t = math.floor(math.sqrt(2 * N))
		if t * (t + 1) // 2 == N:
			return 1
		return 0


class Solution:

	def isTriangular(self, N):
		x = int(math.sqrt(2 * N))
		if x * (x + 1) == 2 * N:
			return 1
		return 0


class Solution:

	def isTriangular(self, N):
		n = 1 + 8 * N
		k = int(n ** 0.5)
		if k * k == n:
			return 1
		return 0


class Solution:

	def isTriangular(self, N):
		c = -2 * N
		(a, b) = (1, 1)
		d = b * b - 4 * a * c
		if d < 0:
			return 0
		root1 = (-b + math.sqrt(d)) / 2 * a
		root2 = (-b - math.sqrt(d)) / 2 * a
		if root1 > 0 and int(root1) == root1:
			return 1
		if root2 > 0 and int(root2) == root2:
			return 1
		return 0


class Solution:

	def isTriangular(self, N):
		k = (-1 + (1 + 8 * N) ** (1 / 2)) // 2
		i = k * (k + 1) // 2
		if i == N:
			return 1
		return 0
import math
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		ob = Solution()
		print(ob.isTriangular(N))


class Solution:

	def isTriangular(self, N):
		x = int(math.sqrt(2 * N))
		if x * (x + 1) == 2 * N:
			return 1
		return 0
import math
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		ob = Solution()
		print(ob.isTriangular(N))


class Solution:

	def isTriangular(self, N):
		if N < 0:
			return 0
		if N == 0:
			return 1
		a = 1
		b = 1
		c = -2 * N
		d = b * b - 4 * a * c
		if d < 0:
			return 0
		r1 = (-b + math.sqrt(d)) / (2 * a)
		r2 = (-b - math.sqrt(d)) / (2 * a)
		if r1 > 0 and math.floor(r1) == r1:
			return 1
		if r2 > 0 and math.floor(r2) == r2:
			return 1
		return 0
import math
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		ob = Solution()
		print(ob.isTriangular(N))


class Solution:

	def isTriangular(self, N):
		k = int((2 * N) ** 0.5)
		j = k * (k + 1) / 2
		if j == N:
			return 1
		return 0


import math

class Solution:

	def isTriangular(self, N):
		p = N * 2
		i = int(math.sqrt(p))
		if i * i + i == p:
			return 1
		return 0


class Solution:

	def isTriangular(self, N):
		N = N * 8 + 1
		sq = N ** 0.5
		if int(sq) == sq:
			return 1
		return 0


class Solution:

	def isTriangular(self, N):
		tri = ((1 + 8 * N) ** 0.5 - 1) / 2
		if tri == int(tri):
			return 1
		else:
			return 0


from math import sqrt

class Solution:

	def isTriangular(self, N):
		if N < 0:
			return 0
		c = -2 * N
		d = 1 + 8 * N
		if d < 0:
			return 0
		a = (-1 + sqrt(d)) / 2
		b = (-1 - sqrt(d)) / 2
		if a > 0 and int(a) == a:
			return 1
		if b > 0 and int(b) == b:
			return 1
		return 0


class Solution:

	def isTriangular(self, N):
		a = int(pow(2 * N, 0.5))
		if a * (a + 1) == 2 * N:
			return 1
		return 0


class Solution:

	def isTriangular(self, N):
		a = (-1 + pow(1 + 8 * N, 0.5)) / 2
		if a % 1 == 0:
			return 1
		else:
			return 0


import math

class Solution:

	def isTriangular(self, N):
		n = int(math.sqrt(N * 2))
		if n * (n + 1) // 2 == N:
			return 1
		else:
			return 0


class Solution:

	def isTriangular(self, N):
		t = N * 2
		s = int(t ** (1 / 2))
		if s * (s + 1) == t or s * (s - 1) == t:
			return 1
		return 0


import math

class Solution:

	def isTriangular(self, n):
		n = n * 8 + 1
		a = math.sqrt(n)
		if int(a) == a:
			return 1
		return 0


import math

class Solution:

	def isTriangular(self, N):
		d = math.sqrt(1 + 8 * N)
		if d.is_integer() and d > 0:
			return 1
		else:
			return 0


class Solution:

	def isTriangular(self, N):
		out = 1 + 8 * N
		out = pow(out, 0.5) - 1
		if int(out) == out:
			return 1
		return 0


import math

class Solution:

	def isTriangular(self, N):
		i = int((N * 2) ** (1 / 2))
		if N * 2 % i == 0 and N * 2 == i * (i + 1):
			return 1
		else:
			return 0


class Solution:

	def isTriangular(self, N):
		i = math.floor(math.sqrt(2 * N))
		return int(i * (i + 1) // 2 == N)


class Solution:

	def isTriangular(self, N):
		import math
		x = -1 + math.sqrt(1 + 8 * N)
		if x % 2 == 0:
			return 1
		return 0


import math

class Solution:

	def isTriangular(self, N):
		n = math.sqrt(1 + 8 * N) / 2 - 0.5
		if n.is_integer():
			return 1
		else:
			return 0


import math

class Solution:

	def isTriangular(self, N):
		self.N = N
		self.sum = 0
		self.summ = 0
		self.sum = (-1 + math.sqrt(1 + 8 * self.N)) / 2
		self.summ = (-1 - math.sqrt(1 + 8 * self.N)) / 2
		if (self.sum or self.summ) <= 0:
			return 0
		elif self.sum % 1 == 0:
			return 1
		elif self.summ == 0:
			return 1
		else:
			return 0


from math import *

class Solution:

	def isTriangular(self, N):
		val = floor(sqrt(2 * N))
		if val * (val + 1) == 2 * N:
			return 1
		return 0