Given a number N, the task is find the number of ways to represent this number as a sum of 2 or more consecutive natural numbers.
 
Example 1:
Input:
N = 10
Output:
1
Explanation:
10 can be reprsented as sum of two or
more consecutive numbers in only one
way. 10 = 1+2+3+4.
Example 2:
Input:
N = 15
Output:
3
Explanation:
15 can be reprsented as sum of two or
more consecutive numbers in 3 ways.
(15 = 1+2+3+4+5); (15 = 4+5+6); (15 = 7+8).
 
Your Task:
You don't need to read input or print anything. Your task is to complete the function getCount() which takes an Integer n as input and returns the answer.
 
Expected Time Complexity: O(sqrt(N))
Expected Auxiliary Space: O(1)
 
Constraints:
1 <= N <= 10^{8}

Source: geeksforgeeks | Difficulty: MEDIUM
Tags: Mathematics

Starter code: #User function Template for python3



class Solution:

    def getCount(self, N):

        # code here 

Solutions:
class Solution:

	def getCount(self, N):
		c = 0
		l = 1
		while l * (l + 1) < 2 * N:
			a = (1.0 * N - l * (l + 1) / 2) / (l + 1)
			if a - int(a) == 0.0:
				c += 1
			l += 1
		return c


class Solution:

	def getCount(self, N):
		n = N
		l = 1
		cnt = 0
		while l * (l + 1) < 2 * n:
			a = (n - l * (l + 1) // 2) / (l + 1)
			if a == int(a):
				cnt += 1
			l += 1
		return cnt


import math

class Solution:

	def getCount(self, N):
		if N == 1:
			return 0
		ans = 0
		if N % 2 == 1:
			ans = 1
			for i in range(3, int(math.sqrt(N)) + 1, 2):
				if N % i == 0:
					ans += 1
					if i * i != N:
						ans += 1
		else:
			for i in range(2, int(math.sqrt(N)) + 1):
				if N % i == 0 and (N // i % 2 == 1 or i % 2 == 1):
					ans += 1
		return ans


class Solution:

	def getCount(self, N):
		k = 2
		res = 0
		while 2 * N > k * (k - 1):
			if (N - k * (k - 1) // 2) % k == 0:
				res += 1
			k += 1
		return res


class Solution:

	def getCount(self, N):
		ans = 0
		L = 1
		while L * (L + 1) / 2 < N:
			a = (N - L * (L + 1) / 2) / (L + 1)
			if a > 0 and a == int(a):
				ans += 1
			L += 1
		return ans


class Solution:

	def getCount(self, N):
		count = 0
		L = 1
		while L * (L + 1) < 2 * N:
			a = (1.0 * N - L * (L + 1) / 2) / (L + 1)
			if a - int(a) == 0.0:
				count += 1
			L += 1
		return count


from collections import defaultdict
from bisect import *
import math

class Solution:

	def getCount(self, n):
		ans = 0
		for k in range(2, int((2 * n) ** 0.5) + 1):
			if (n - k * (k - 1) // 2) % k == 0:
				ans += 1
		return ans


from collections import defaultdict
import math

class Solution:

	def getCount(self, N):
		ans = 0
		for k in range(2, int(math.sqrt(2 * N) + 1)):
			if (N - k * (k - 1) / 2) % k == 0:
				ans += 1
		return ans


import math

class Solution:

	def getCount(self, N):
		s = 0
		l = 1
		li = l * (l + 1) / 2
		while li < N:
			a = (N - li) / (l + 1)
			if a - int(a) == 0.0:
				s = s + 1
			l = l + 1
			li = l * (l + 1) / 2
		return s


class Solution:

	def getCount(self, N):
		c = 0
		for j in range(2, N + 1):
			if j * j < 2 * N:
				if N > j * (j - 1) // 2:
					if (N - j * (j - 1) // 2) % j == 0:
						c += 1
			elif j * j >= 2 * N:
				break
		return c


class Solution:

	def getCount(self, N):
		c = 0
		k = 1
		while N - k > 0:
			N = N - k
			if N % (k + 1) == 0:
				c += 1
			k += 1
		return c


class Solution:

	def getCount(self, N):
		count = 0
		chain_length = 0
		sum = 0
		while sum < N:
			chain_length = chain_length + 1
			sum = sum + chain_length
		for L in range(1, chain_length):
			a = (N - L * (L + 1) / 2) / (L + 1)
			if a == int(a):
				count += 1
		return count


class Solution:

	def getCount(self, n):
		count = 0
		i = 1
		while i * (i + 1) < n * 2:
			a = (n - i * (i + 1) / 2) / (i + 1)
			if a - int(a) == 0:
				count += 1
			i += 1
		return count


class Solution:

	def getCount(self, N):
		if N == 1 or N == 2:
			return 0
		count = 0
		for k in range(2, int((N * 2) ** 0.5) + 1):
			if (N - k * (k - 1) / 2) % k == 0:
				count += 1
		return count


import math

class Solution:

	def getCount(self, n):
		ans = 0
		for i in range(1, int(math.sqrt(2 * n)) + 1):
			val = int(n - i * (i - 1) // 2)
			if val % i == 0:
				ans += 1
		return ans - 1


class Solution:

	def getCount(self, N):
		m = 0
		j = int((2 * N) ** (1 / 2))
		count = 0
		if N == 1:
			return 0
		for i in range(2, int((2 * N) ** (1 / 2)) + 1):
			k = N - i * (i - 1) / 2
			if (N - i * (i - 1) / 2) % i == 0:
				count += 1
		return count


import math

class Solution:

	def getCount(self, N):
		ct = 0
		maxN = math.ceil((math.sqrt(8 * N + 1) - 1) / 2)
		for n in range(2, maxN + 1):
			a = N / n - (n - 1) / 2
			if a == round(a):
				ct += 1
		return ct


class Solution:

	def getCount(self, N):
		no_of_step = 0
		chaincout = 0
		while chaincout < N:
			no_of_step += 1
			chaincout += no_of_step
		count = 0
		for L in range(1, no_of_step):
			a = (N - L * (L + 1) / 2) / (L + 1)
			if a == int(a):
				count += 1
		return count


import math

class Solution:

	def getCount(self, N):
		ans = 0
		L = 1
		while L * (L + 1) < 2 * N:
			s = L * (L + 1) / 2
			a = (N - s) / (L + 1)
			if math.ceil(a) == math.floor(a):
				ans += 1
			L += 1
		return ans


from math import ceil, sqrt

def sus(i, n):
	return n * (n + 1) // 2 - i * (i + 1) // 2

class Solution:

	def getCount(self, N):
		c = 0
		for i in range(2, N):
			t = N // i - (i - 1) // 2
			if t > 0:
				if sus(t - 1, t + i - 1) == N:
					c += 1
			else:
				break
		return c


class Solution:

	def getCount(self, N):
		if N < 3:
			return 0
		count = 0
		maxk = int((2 * N) ** 0.5) + 1
		for k in range(1, maxk + 1):
			if (2 * N - k ** 2 - k) % (2 * k + 2) == 0:
				n = (2 * N - k ** 2 - k) / (2 * k + 2)
				if n >= 1:
					count += 1
		return count


import math as m

class Solution:

	def getCount(self, N):
		ans = 0
		x = m.sqrt(2 * N)
		x = int(x)
		for k in range(2, x + 1):
			if (N - k * (k - 1) / 2) % k == 0:
				ans += 1
		return ans


class Solution:

	def getCount(self, n):
		c = 0
		sm = 0
		chain_len = 0
		while sm < n:
			chain_len += 1
			sm += chain_len
		for i in range(1, chain_len):
			a = (n - i * (i + 1) / 2) / (i + 1)
			if a == int(a):
				c += 1
		return c


class Solution:

	def getCount(self, N):
		count = 0
		sums = 0
		chain_length = 0
		while sums < N:
			chain_length += 1
			sums += chain_length
		for i in range(1, chain_length):
			a = (N - i * (i + 1) / 2) / (i + 1)
			if a == int(a):
				count += 1
		return count


import math

class Solution:

	def getCount(self, N):
		cnt = 0
		for l in range(1, int(math.sqrt(2 * N)) + 1):
			a = N / (l + 1) - l / 2
			if int(a) == a and a >= 1:
				cnt = cnt + 1
		return cnt


import math

class Solution:

	def getCount(self, N):
		counter = 0
		maxNum = math.ceil((math.sqrt(8 * N + 1) - 1) / 2)
		for num in range(2, maxNum + 1):
			res = N / num - (num - 1) / 2
			if res == round(res):
				counter += 1
		return counter


class Solution:

	def getCount(self, N):
		ans = 0
		p = 0
		while N > p * (p + 1) // 2:
			p += 1
		for r in range(2, p + 1):
			if (N - r * (r + 1) // 2) % r == 0:
				ans += 1
		return ans


class Solution:

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


class Solution:

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


from math import sqrt, floor

class Solution:

	def getCount(self, N):
		count = 0
		L = 2
		while L * (L - 1) < 2 * N:
			if (1.0 * N - L * (L - 1) / 2) % L == 0:
				count += 1
			L += 1
		return count
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		ob = Solution()
		print(ob.getCount(N))


class Solution:

	def getCount(self, N):
		count = 0
		L = 1
		while L * (L + 1) < 2 * N:
			a = (1.0 * N - L * (L + 1) / 2) / (L + 1)
			if a - int(a) == 0.0:
				count += 1
			L += 1
		return count
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		ob = Solution()
		print(ob.getCount(N))


import math

class Solution:

	def getCount(self, N):
		ans = 0
		y = 1
		while y * (y + 1) < 2 * N:
			diff = (N - y * (y + 1) / 2) / (y + 1)
			if diff - int(diff) == 0.0:
				ans += 1
			y += 1
		return ans
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		ob = Solution()
		print(ob.getCount(N))


import math

class Solution:

	def getCount(self, N):
		r = 0
		for i in range(2, int(math.sqrt(N * 2) + 1)):
			if i % 2 == 0:
				if (N + i / 2) % i == 0:
					r += 1
			elif N % i == 0:
				r += 1
		return r


class Solution:

	def getCount(self, N):
		count = 0
		twoN = N * 2
		l = 1
		while l * (l + 1) < twoN:
			mod1 = N % (l + 1)
			mod2 = l % 2
			if mod1 == 0 and mod2 == 0:
				count += 1
			elif mod2 == 1 and mod1 * 2 == l + 1:
				count += 1
			l += 1
		return count


class Solution:

	def getCount(self, N):
		ans = 0
		i = 2
		while i * (i - 1) / 2 < N:
			if (N - i * (i - 1) / 2) % i == 0:
				ans += 1
			i += 1
		return ans


class Solution:

	def getCount(self, n):
		chain = 0
		c = 0
		k = 0
		while chain <= n:
			k = k + 1
			chain = k * (k + 1) / 2
		for i in range(1, k - 1):
			a = n / (i + 1) - i / 2
			if a == int(a):
				c = c + 1
		return c


class Solution:

	def getCount(self, N):
		res = 0
		n = 2
		while 2 * N + n - n ** 2 > 0:
			a = (2 * N + n - n ** 2) / (2 * n)
			if a - int(a) == 0:
				res += 1
			n += 1
		return res


import math

class Solution:

	def getCount(self, N):
		cnt = 0
		maxi = math.ceil((math.sqrt(8 * N + 1) - 1) / 2)
		for i in range(2, maxi + 1):
			val = N / i - (i - 1) / 2
			if val == round(val):
				cnt += 1
		return cnt


class Solution:

	def getCount(self, N):
		count = 0
		i = 2
		while 2 * N - pow(i, 2) + i > 0:
			a = (2 * N - pow(i, 2) + i) / (2 * i)
			if a - int(a) == 0:
				count += 1
			i += 1
		return count


class Solution:

	def getCount(self, n):
		count = 0
		sum = 0
		chain_length = 0
		while sum < n:
			chain_length += 1
			sum += chain_length
		for l in range(1, chain_length):
			a = n / (l + 1) - l / 2
			if a == int(a):
				count += 1
		return count


class Solution:

	def getCount(self, N):
		mod = 10000000000.0 + 7
		cnt = 0
		i = 2
		while i * (i - 1) // 2 < N:
			if (N - i * (i - 1) // 2) % i == 0:
				cnt += 1
			i += 1
		return cnt


class Solution:

	def getCount(self, n):
		count = 0
		curSum = 0
		chainLen = 0
		while curSum < n:
			chainLen += 1
			curSum += chainLen
		for i in range(1, chainLen):
			a = (n - i * (i + 1) / 2) / (i + 1)
			if a.is_integer():
				count += 1
		return count


class Solution:

	def getCount(self, N):
		tot_sum = 0
		l = 1
		while tot_sum < N:
			tot_sum += l
			l += 1
		count = 0
		for i in range(1, l):
			a = N - i * (i + 1) / 2
			if a % (i + 1) == 0 and a != 0:
				count += 1
		return count


from math import *

class Solution:

	def getCount(self, N):
		c = 0
		i = 2
		while 2 * N > i * (i - 1):
			n = (N * 1.0 - i * (i - 1) / 2) / i
			if n - int(n) == 0.0:
				c += 1
			i += 1
		return c


class Solution:

	def getCount(self, N):
		if N < 3:
			return 0
		cnt = 0
		i = 2
		while i * (i - 1) / 2 < N:
			if (N - i * (i - 1) / 2) % i == 0:
				cnt += 1
			i += 1
		return cnt


import math

class Solution:

	def getCount(self, N):
		lim = 0
		while lim * (lim + 1) // 2 < N:
			lim += 1
		count = 0
		for k in range(2, lim + 1):
			a = (2 * N / k - k + 1) / 2
			if a > 0 and a <= N and (int(a) == a):
				count += 1
		return count


import math

class Solution:

	def getCount(self, N):
		res = 0
		i = 1
		while i * (i + 1) < 2 * N:
			tmp = (N - i * (i + 1) / 2) / (i + 1)
			if tmp - int(tmp) == 0.0:
				res += 1
			tmp = i * (i + 1) // 2
			i += 1
		return res


class Solution:

	def getCount(self, N):
		ans = 0
		for i in range(2, N):
			dif = N - i * (i - 1) // 2
			if i > dif:
				break
			if dif % i == 0:
				ans += 1
		return ans


class Solution:

	def getCount(self, N):
		count = 0
		chain_len = 0
		sum1 = 0
		while sum1 < N:
			chain_len += 1
			sum1 += chain_len
		for L in range(1, chain_len):
			a = (N - L * (L + 1) / 2) / (L + 1)
			if a == int(a):
				count += 1
		return count