human
Count ways to express a number as sum of consecutive numbers | Utility method to compute number of ways in which N can be represented as sum of consecutive number.
constraint on values of L gives us the time Complexity as O ( N ^ 0.5 ).
Driver code"
How can the above be solved in Python?
assistant
#Here is code to count ways to express a number as sum of consecutive numbers and the other steps required.
 def countConsecutive ( 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
N = 15
print countConsecutive ( N )
N = 10
print countConsecutive ( N )