While traveling on an interstate highway, I noticed a sign that gave distances to three places. The distances were 3, 8, and 9 miles, or a prime, a perfect cube, and a perfect square. I then wondered whether it was possible to express integers (above a certain value) as the sum of a prime, a square, and a cube. For example, 11 can be expressed as
, and 17 can be expressed as
or
.
Write a function to list ways to express numbers as the sum of a prime, a square, and a cube. All three must be positive. The function should return a matrix the primes in the first column, the squares in the second, and the cubs in the third, and the rows should be sorted by the first column and then the second. Given an input of 11, the function should return [2 1 8], and given an input of 17, the function should return [5 4 8; 7 9 1]. If the input cannot be expressed in this way, return the empty vector [].
Optional: Prove that all integers greater than 6 can be expressed as the sum of a prime, a square, and a cube.
Solution Stats
Problem Comments
2 Comments
Solution Comments
Show comments
Loading...
Problem Recent Solvers7
Suggested Problems
-
16474 Solvers
-
Flag largest magnitude swings as they occur
690 Solvers
-
540 Solvers
-
Create an index-powered vector
941 Solvers
-
Find and replaces spaces from a input string with *
172 Solvers
More from this Author323
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
The prime, perfect cube and perfect square all have to be strictly positive - otherwise you'll also get decompositions such as 11 = 3 + 4^2 + (-2)^3, which is not intended.
Right. Thanks. I added that bit to the description.