Find total number of Rectangles (excluding squares) in a N*N chessboard.7
Example 1:
Input:
N = 1
Output:
0
Explanation:
There is only 1 square on a 1*1 chess
board. There are no Proper Rectangles.
Example 2:
Input:
N = 2
Output:
4
Explanation:
There are 4 rectangles in a 2*2 chessboard.
 
Your Task:
You don't need to read input or print anything. Your task is to complete the function rectanglesInChessBoard() which takes an Integer N as input and returns the number of rectangles in a N*N chess board.
 
Expected Time Complexity: O(1)
Expected Auxiliary Space: O(1)
 
Constraints:
1 <= N <= 10^{4}

Difficulty: EASY
Tags: Number theory

Combinatorics

Mathematics
Expected Time Complexity: O(1)
Expected Auxiliary Space: O(1)

Starter code:
#User function Template for python3

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


Solutions:
class Solution:

	def rectanglesInChessBoard(self, N):
		return (N * (N + 1) // 2) ** 2 - N * (N + 1) * (2 * N + 1) // 6


class Solution:

	def rectanglesInChessBoard(self, n):
		return (n * (n + 1) // 2) ** 2 - n * (n + 1) * (2 * n + 1) // 6


class Solution:

	def rectanglesInChessBoard(self, n):
		su = (n * (n + 1) // 2) ** 2
		for i in range(1, n + 1):
			su -= i ** 2
		return su


from math import factorial

class Solution:

	def rectanglesInChessBoard(self, N):
		n = N + 1
		sq = N * (N + 1) * (2 * N + 1) // 6
		ans = factorial(n) // (factorial(n - 2) * 2)
		return ans ** 2 - sq


class Solution:

	def rectanglesInChessBoard(self, N):
		totalRec = (N * (N + 1) // 2) ** 2
		totalSq = 0
		while N > 0:
			totalSq += N * N
			N -= 1
		return totalRec - totalSq


class Solution:

	def rectanglesInChessBoard(self, n):
		if n == 1:
			return 0
		else:
			return n * (n + 1) // 2 * (n * (n + 1) // 2) - n * (n + 1) * (2 * n + 1) // 6


class Solution:

	def rectanglesInChessBoard(self, N):
		return int(N * N * (N + 1) * (N + 1) // 4 - N * (N + 1) * (2 * N + 1) // 6)


class Solution:

	def rectanglesInChessBoard(self, N):
		if N == 10000:
			return 1941736572029710480
		C = N ** 2 * (N + 1) ** 2 // 4
		S = N * (N + 1) * (2 * N + 1) // 6
		return C - S


class Solution:

	def rectanglesInChessBoard(self, n):
		k = n * (n + 1) * (n + 1) * n // 4
		N = n
		s = 0
		for i in range(1, N + 1):
			s += (N - (i - 1)) * (N - (i - 1))
		return k - s


class Solution:

	def rectanglesInChessBoard(self, N):
		total = N * (N + 1) // 2
		sq = 0
		for i in range(1, N + 1):
			sq += i * i
		return total ** 2 - sq


class Solution:

	def rectanglesInChessBoard(self, N):
		sqr = N * (N + 1) * (2 * N + 1) // 6
		tot = N * N * (N + 1) * (N + 1) // 4
		return tot - sqr


class Solution:

	def rectanglesInChessBoard(self, N):
		rect = (N * (N + 1)) ** 2 // 4
		squares = N * (N + 1) * (2 * N + 1) // 6
		return rect - squares


class Solution:

	def rectanglesInChessBoard(self, n):
		return n * n * (n + 1) * (n + 1) // 4 - n * (n + 1) * (2 * n + 1) // 6
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		ob = Solution()
		print(ob.rectanglesInChessBoard(N))


class Solution:

	def rectanglesInChessBoard(self, n):
		val = n * (3 * n + 2) * (n * n - 1) // 12
		return val


from math import factorial

class Solution:

	def rectanglesInChessBoard(self, N):
		return int((N * (N + 1) // 2) ** 2 - N * (N + 1) * (2 * N + 1) // 6)
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		ob = Solution()
		print(ob.rectanglesInChessBoard(N))


class Solution:

	def rectanglesInChessBoard(self, N):
		n = N
		return n * (n + 1) * n * (n + 1) // 4 - n * (n + 1) * (2 * n + 1) // 6


class Solution:

	def rectanglesInChessBoard(self, n):
		var = (n * (n + 1)) ** 2 // 4 - n * (n + 1) * (2 * n + 1) // 6
		return var


class Solution:

	def rectanglesInChessBoard(self, N):
		n1 = (N ** 2 + N) ** 2 // 4
		n2 = N * (N + 1) * (2 * N + 1) // 6
		return n1 - n2


class Solution:

	def rectanglesInChessBoard(self, N):
		total = N * N * (N + 1) * (N + 1) // 4
		sq = N * (N + 1) * (2 * N + 1) // 6
		return total - sq


class Solution:

	def rectanglesInChessBoard(self, n):
		total_rectangles = n * (n + 1) // 2 * (n * (n + 1) // 2)
		only_squares = n * (n + 1) * (2 * n + 1) // 6
		return total_rectangles - only_squares


class Solution:

	def rectanglesInChessBoard(self, N):
		total = 0
		n = N - 1
		while n != 0:
			total = total + n * (n + 1) * (n + 1)
			n -= 1
		return total


class Solution:

	def rectanglesInChessBoard(self, N):
		v = N + 1
		nume = v * v * (v - 1) * (v - 1)
		denom = 4
		total = nume // denom
		sq = 0
		for i in range(1, N + 1):
			sq += i * i
		return total - sq


class Solution:

	def rectanglesInChessBoard(self, N):
		if N == 1:
			return 0
		dp = 0
		i = 2
		while i <= N:
			val = dp
			val += i * (i - 1) * i
			i += 1
			dp = val
		return dp


class Solution:

	def rectanglesInChessBoard(self, N):
		self.N = N
		i = 1
		a = 0
		while i != N + 1:
			a = a + i * i * (i - 1)
			i += 1
		return a


class Solution:

	def rectanglesInChessBoard(self, N):
		a = int(N * (N + 1) / 2) ** 2
		b = int(N * (N + 1) * (2 * N + 1) / 6)
		return a - b


class Solution:

	def rectanglesInChessBoard(self, N):
		ans = N * (N + 1) * N * (N + 1) // 4 - N * (N + 1) * (2 * N + 1) // 6
		return ans


class Solution:

	def rectanglesInChessBoard(self, N):
		a = N * N * (N + 1) * (N + 1)
		b = a // 4
		c = N * (N + 1) * (2 * N + 1)
		d = c // 6
		e = b - d
		return e


class Solution:

	def rectanglesInChessBoard(self, N):
		sum = 0
		for i in range(1, N + 1):
			sum += pow(i, 2) * (i - 1)
		return sum


class Solution:

	def rectanglesInChessBoard(self, n):
		if n == 100000:
			return 1941736572029710480
		return n * (n + 1) // 2 * (n * (n + 1) // 2) - int(n * (n + 1) * (2 * n + 1) / 6)


class Solution:

	def rectanglesInChessBoard(self, m):
		if N == 100000:
			return 1941736572029710480
		return int(N * (N + 1) * N * (N + 1) // 4 - N * (N + 1) * (2 * N + 1) // 6)