L
L
Lesha Yes2019-12-07 09:08:48
Python
Lesha Yes, 2019-12-07 09:08:48

Python: In how many ways can a given natural number N be represented as a sum of consecutive odd natural numbers?

In how many ways can a given natural number N be represented as a sum of successive
odd natural numbers? One number is not considered a "sum".

Example: 16 can be represented in two ways 1 + 3 + 5 + 7 = 16 and 7 + 9 = 16.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
Wataru, 2019-12-09
@asyl_narul

The sum of consecutive odd numbers is the difference of two squares: 1
+ 3 + 5 + 7 = 16 - 0
7 + 9 = 25 - 9 b^2 = (ab)(a+b) Or how many numbers a and b, incl. N is factorized into (a+b) and (ab). It suffices to find all divisors of N (not greater than the root), incl. the divisor and the rest have an even difference (this difference is equal to 2b). Those. (n/d - d) %2 = 0. Try all the numbers d up to the root N, and if N%d == 0 and (N/d -d) %2 == 0, then add one to the answer.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question