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
-
Square Digits Number Chain Terminal Value (Inspired by Project Euler Problem 92)
254 Solvers
-
Is the paranthesis sequence balanced ?
200 Solvers
-
90 Solvers
-
Calculate compression ratio of engine
220 Solvers
-
Chebyshev polynomials of the 1st Kind
80 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.