Cody

Problem 42935. Sums of cubes and squares of sums

Created by John D'Errico in Community

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.

Solution Stats

33.93% Correct | 66.07% Incorrect
Last solution submitted on Jun 16, 2019

Problem Comments

Solution Comments