Computer Science, asked by thakurmaninder5622, 1 year ago

Count ways to express the count ways to express a number as sum of consecutive numbers

Answers

Answered by vamsimullapudi364
0

The idea is to represent N as a sequence of length L+1 as:

N = a + (a+1) + (a+2) + .. + (a+L)

=> N = (L+1)*a + (L*(L+1))/2

=> a = (N- L*(L+1)/2)/(L+1)

We substitute the values of L starting from 1 till L*(L+1)/2 < N

If we get 'a' as a natural number then the solution should be counted.

Similar questions