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.
why it is showing--"While evaluating the solution, the server encountered an error caused by temporary unavailability of MATLAB Service'' ...
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.
4444 Solvers
We love vectorized solutions. Problem 1 : remove the row average.
626 Solvers
3495 Solvers
345 Solvers
463 Solvers
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!