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.
I had to cheat to get the test 1 to pass. The test requires that if N=1, then politeness=0. According to other reputable sources, politeness of 1 is 1.
then why politeness of 15 isn't 4?
Make the vector [1 2 3 4 5 6 7 8 9 10]
Find the alphabetic word product
Test for balanced parentheses
Test if a Number is a Palindrome without using any String Operations
Getting the indices from a matrice
Arithmetic/geometric sequence, 50/50
Modify subscripts - easier
Packing oranges - one layer
(Linear) Recurrence Equations - Generalised Fibonacci-like sequences
Find the treasures in MATLAB Central and discover how the community can help you!
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Contact your local office