Given a single integer N, your task is to find the sum of the square of the first N odd natural Numbers.
 
Example 1:
Input: 2
Output: 10
Explanation: 1^{2 + }3^{2}^{ }= 10
Example 2: 
Input: 3
Output: 35
Explanation: 1^{2} + 3^{2} + 5^{2} = 35
 
Your Task:
You don't need to read or print anything. Your task is to complete the function sum_of_square_oddNumbers() which takes N as the input parameter and returns the sum of the first N odd natural numbers.
 
Expected Time Complexity: O(1)
Expected Space Complexity: O(1)
 
Constraints:
1 <= N <= 10000

Source: geeksforgeeks | Difficulty: EASY
Tags: Mathematics

Starter code: 

class Solution:

	def sum_of_square_oddNumbers(self, n):

		# Code here

Solutions:
class Solution:

	def sum_of_square_oddNumbers(self, N):
		total = 0
		for i in range(1, 2 * N, 2):
			total += i ** 2
		return total


class Solution:

	def sum_of_square_oddNumbers(self, n):
		return n * (2 * n + 1) * (2 * n - 1) // 3


class Solution:

	def sum_of_square_oddNumbers(self, n):
		square = 1
		sum = 0
		for i in range(1, n + 1):
			sum += square * square
			square += 2
		return sum


class Solution:

	def sum_of_square_oddNumbers(self, n):
		sum = 0
		odd = 1
		while n > 0:
			if odd % 2 != 0:
				sum += odd * odd
				odd += 2
				n -= 1
		return sum


class Solution:

	def sum_of_square_oddNumbers(self, n):
		s = 0
		od = range(1, 10000000, 2)
		for i in range(n):
			s = s + od[i] ** 2
		return s


class Solution:

	def sum_of_square_oddNumbers(self, n):
		s = 0
		a = 1
		for i in range(1, n + 1):
			s += a * a
			a += 2
		return s


import math

class Solution:

	def sum_of_square_oddNumbers(self, n):
		(sum, j) = (0, 1)
		for i in range(n):
			sum += math.pow(j, 2)
			j += 2
		return int(sum)


class Solution:

	def sum_of_square_oddNumbers(self, n):
		h = n * (2 * n + 1) * (2 * n - 1) / 3
		return int(h)


class Solution:

	def sum_of_square_oddNumbers(self, n):
		return n * (4 * n * n - 1) // 3


class Solution:

	def sum_of_square_oddNumbers(self, n):
		count = 0
		for i in range(1, n * 2):
			if i % 2 != 0:
				count += i ** 2
		return count


class Solution:

	def sum_of_square_oddNumbers(self, n):
		sum = 0
		ini = 1
		count = 1
		if ini % 2 != 0:
			while count <= n:
				sum += ini ** 2
				ini += 2
				count += 1
		return sum


class Solution:

	def sum_of_square_oddNumbers(self, n):
		res = 1
		i = 1
		for u in range(n - 1):
			i += 2
			res += i ** 2
		return res


class Solution:

	def sum_of_square_oddNumbers(self, n):
		nums = 0
		nums = n
		start = 1
		sum = 0
		while nums != 0:
			sum = sum + start ** 2
			start += 2
			nums -= 1
		return sum


class Solution:

	def sum_of_square_oddNumbers(self, n):
		sum = 0
		num = 1
		for i in range(1, n + 1):
			sq = num * num
			sum = sum + sq
			num = num + 2
		return sum


class Solution:

	def sum_of_square_oddNumbers(self, n):
		s = 0
		c = 1
		i = 0
		while i < n:
			s += c ** 2
			c += 2
			i += 1
		return s


class Solution:

	def sum_of_square_oddNumbers(self, n):
		su = 0
		x = 1
		for i in range(n):
			su += x ** 2
			x += 2
		return su


import math

class Solution:

	def sum_of_square_oddNumbers(self, n):
		return n * (4 * n * n - 1) // 3


class Solution:

	def sum_of_square_oddNumbers(self, n):
		total = 0
		counter = 1
		for i in range(n):
			total = total + counter * counter
			counter = counter + 2
		return total


class Solution:

	def sum_of_square_oddNumbers(self, n):
		res = 0
		for i in range(2 * n):
			if i % 2 != 0:
				res += i ** 2
		return res


class Solution:

	def sum_of_square_oddNumbers(self, n):
		(i, out, j) = (0, 0, 1)
		while i < n:
			out += j ** 2
			j += 2
			i += 1
		return out


class Solution:

	def sum_of_square_oddNumbers(self, n):
		k = 0
		for i in range(n):
			k += (2 * i + 1) ** 2
		return k


class Solution:

	def sum_of_square_oddNumbers(self, n):
		sum = n * (2 * n + 1) * (2 * n - 1) / 3
		return int(sum)


class Solution:

	def sum_of_square_oddNumbers(self, n):
		i = 1
		count = 0
		su = 0
		while True:
			if count != n:
				su = su + i ** 2
				count += 1
				i = i + 2
			else:
				break
		return su


class Solution:

	def sum_of_square_oddNumbers(self, n):
		return sum([(1 + 2 * x) ** 2 for x in range(0, n)])


class Solution:

	def sum_of_square_oddNumbers(self, n):
		ss = n * (2 * n + 1) * (2 * n - 1) / 3
		return int(ss)


class Solution:

	def sum_of_square_oddNumbers(self, n):
		return int(n * (4 * n ** 2 - 1) / 3)


class Solution:

	def sum_of_square_oddNumbers(self, n):
		m = 1
		s = 0
		while n:
			a = m ** 2
			m += 2
			n -= 1
			s += a
		return s


class Solution:

	def sum_of_square_oddNumbers(self, n):
		i = 1
		count1 = 0
		count2 = 0
		while True:
			if i % 2 != 0:
				count1 = count1 + i ** 2
				count2 = count2 + 1
				if count2 == n:
					break
			i = i + 1
		return count1


class Solution:

	def sum_of_square_oddNumbers(self, N):
		return N * (2 * N - 1) * (2 * N + 1) // 3


class Solution:
	import math

	def sum_of_square_oddNumbers(self, n):
		if n == 1:
			return 1
		return n * (2 * n + 1) * (2 * n - 1) // 3


class Solution:

	def sum_of_square_oddNumbers(self, n):
		even = 2 * n * (n + 1) * (2 * n + 1) // 3
		odd = abs(2 * n * (2 * n + 1) // 2 - even)
		return odd


class Solution:

	def sum_of_square_oddNumbers(self, n):
		e = 2 * n * (n + 1) * (2 * n + 1) // 3
		t = 2 * n * (2 * n + 1) * (4 * n + 1) // 6
		return t - e


class Solution:

	def sum_of_square_oddNumbers(self, n):
		val = 1
		ans = 0
		for i in range(1, n + 1):
			ans += val * val
			val += 2
		return ans