Given the positive integers 1:n, can you:
1. Compute twice the sum of the cubes of those numbers. 2. Subtract the square of the sum of those numbers. 3. Divide that result by n/2.
So, for n = 3, we might compute a result like this:
((1^3 + 2^3 + 3^3)*2 - (1 + 2 + 3)^2)/(3/2) ans = 24
Yes, you probably can do all of this, but be careful on this problem, as n may be somewhat large, and I am expecting to see the correct result, not just an approximate value. Remember there are always different ways one may solve a problem.
I point out the Project Euler reference because PE problem 6 is what made me think of this problem, and because the test cases will push the limits of what you can do if you are not careful.
I did not originally look to see exactly how far one could go. It looks like, IF one is careful in the important expression, you should be able to get to 3329020. I'd expect that the code I'd write that would solve this to go as far as 3329020 would employ an initial test to know if n is even or odd, changing the expression I'd write depending on the parity of n. Of course that branch would also increase the complexity, so raising the Cody score.
it is exactly the right way to solve this one.
works for n up to 3329020
works for n up to 2642245, so it doesn't use the full potential of the uint64
isequal ignores the data type of the values in determining whether they are equal.
isequal(uint64(15503197751395200),15503197751395199,15503197751395201,15503197751395200)
flintmax('double') = 2^53 < 15503197751395200
eps(15503197751395200) = 2
Big letters, small letters and a bit of luck.
Select every other element of a vector
15344 Solvers
5419 Solvers
1268 Solvers
Replace NaNs with the number that appears to its left in the row.
1651 Solvers
164 Solvers