Problem 59701. Express numbers as the sum of a prime, a square, and a cube
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
Christian Schröder
on 16 Mar 2024
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.
ChrisR
on 17 Mar 2024
Right. Thanks. I added that bit to the description.
Solution Comments
Show commentsProblem Recent Solvers5
Suggested Problems
-
Return the 3n+1 sequence for n
8260 Solvers
-
446 Solvers
-
108 Solvers
-
936 Solvers
-
81 Solvers
More from this Author275
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!