A polite number is an integer that sums of two or more consecutive positive integers. Politeness of a positive integer is a number of nontrivial ways to write n as a sum of two or more consecutive positive integers.
For example 9 = 4+5 = 2+3+4 and politeness of 9 is 2.
Given N return politeness of N.
See also 2593
There are some flaws when checking the solutions:
I think 15 has 4 combinations of sum of consecutive INTEGERS (as stated in the problem):
15 = 7+8 = 4+5+6 = 1+2+3+4+5 = 0+1+2+3+4+5; % 0 is integer.
or 1025 (you say 5, I say 9):
1025 = 1022+1023 = sum(203:207) = sum(98:107) = sum(29:53) = sum(5:45) = sum(-4:45) = sum(-28:53) = sum(-97:107) = sum(-202:207); % negative numbers are integers too.
I can see the flaw in the description now, I've missed repeating "positive", Thanks. Btw considering your interpretation 15 has 7 combinations: sum(-14:15),sum(-6:8),sum(-3:6),sum(0:5),sum(1:5),sum(4:6),sum(7:8). In this way 1025 should have 11 and conversion between our interpretations is "yours=2*mine+1"; to any of mine solutions of the form m:n, you can add "-m+1:n", the last thing is to add "-input+1:input"
An interesting problem, enough so that I chose to solve it in three essentially different ways. As always, there are various ways to solve any problem. The first two ways were essentially constructive, so counting the set of solutions for any N. The last used a formulaic approach.
So, doing a little reading about polite numbers, one finds that the politeness divisors is related to the number of odd divisors.
vectorized & constructive, explicitly counting all solutions for even and odd k
Brute force, with a while loop. crude as hell, but it works for a first pass.
Whit this solution you can check the correct number of combinations that summing consecutive integers give the input number.
1771 Solvers
363 Solvers
136 Solvers
Return the first and last character of a string
1614 Solvers
262 Solvers