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 commentsGroup

Prime Numbers III
- 19 Problems
- 4 Finishers
- List the Moran numbers
- List the cuban primes
- Compute the largest number whose prime factors sum to n
- List the Beatriz numbers
- List the Euclid numbers
- List odd twin composites
- List the semiprimes
- Solve an equation involving primes and fractions
- List the two-bit primes
- List numbers such that every sum of consecutive positive integers ending in those numbers is composite
- Identify de Polignac numbers
- List the Fermi-Dirac primes
- Factor a number into Fermi-Dirac primes
- Compute the Sisyphus sequence
- Compute the bubble popper fidget spinner sequence
- Determine whether a number is a Zeisel number
- Express numbers as the sum of a prime, a square, and a cube
- Determine whether a number is a Gaussian prime
- List primes of the form xy+z
Problem Recent Solvers6
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!