Problem 2595. Polite numbers. Politeness.
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
Solution Stats
Problem Comments
-
5 Comments
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.
Politeness is an integer sequence defined at https://oeis.org/A069283.
@Dyuman Joshi: I do not know why that error occurs. I do know that it essentially means that the user needs to wait and re-submit their solution at a later time, sometimes the next day.
By the way, it's best to not post solutions (or solution attempts) in comments. Questions or comments specific to a solution can be posted in a comment tied to said solution or solution attempt.
Solution Comments
Show commentsProblem Recent Solvers173
Suggested Problems
-
18643 Solvers
-
Create a cell array out of a struct
1831 Solvers
-
1111 Solvers
-
5222 Solvers
-
635 Solvers
More from this Author40
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!