Problem statement

https://binarysearch.com/problems/Ways-to-Sum-Consecutive-Numbers-to-N/

Solution

Equal to Leetcode 0829 Consecutive Numbers Sum.

Complexity

Time complexity is O(sqrt(N)), space is O(1).

Code

class Solution:
    def solve(self, N):
        ans = 0
        for k in range(1, ceil(sqrt(2*N))):
            if (k + 2*N/k) % 2 == 1:
                ans += 1
        return ans if N != 0 else 1