Sums of cubes and squares of sums - MATLAB Cody - MATLAB Central

Problem 42935. Sums of cubes and squares of sums

Difficulty:Rate

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

16.52% Correct | 83.48% Incorrect
Last Solution submitted on Feb 19, 2025

Problem Comments

Solution Comments

Show comments

Group

Project Euler II Image
Project Euler II
  • 12 Problems
  • 51 Finishers

Problem Recent Solvers266

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Go to top of page