Your task is to, with an input number
p, find the smallest positive cannonball number of order
p that is NOT 1.
A cannonball number (of order
p) is a number which is both:
p-gonal number (See this page).
p-gonal pyramid number.
p-gonal pyramid number is the sum of the 1st to
4th square pyramid number = 1 + 4 + 9 + 16 = 30)
For more info, visit this link.
The cannonball number of order 3, for example, is 10, because it is:
- The fourth triangle number (
1 + 2 + 3 + 4 = 10)
- and the third triangular pyramid number. (
1 + 3 + 6 = 10)
NOTE: If you can find (or make) more useful formulae than my ones here, please post it here (or message me on the question chat thing).
- If you're interested, the formula for the
p-gonal number is:
- And the
p-gonal pyramid number is:
pis guaranteed to be larger than 2.
- The program must check values for a solution for
pup to (and including)
2^16. Your program may do anything if no solutions are found for
- Only positive indices for
10(4th triangle number, 3rd triangle pyramid number)
4900(70th square number, 24th square pyramid number)
This is code-golf, so shortest answer in bytes wins.
Note: If you do post a solution, please include a description of how the code works.
Should I start a bounty for a solution which is better and doesn't use my formulae?