Your task is to, with an input number p
, find the smallest positive cannonball number of order p
that is NOT 1.
Definition
A cannonball number (of order p
) is a number which is both:
- An
p
-gonal number (See this page). and an
p
-gonal pyramid number.- The
n
thp
-gonal pyramid number is the sum of the 1st ton
thp
-gonal numbers.- (e.g.
4th square pyramid number = 1 + 4 + 9 + 16 = 30
)
- (e.g.
The picture below represents the 4th square pyramid number, as a square pyramid.
For more info, visit this link.
- The
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
)
Formulas
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
n
thp
-gonal number is:
- And the
n
thp
-gonal pyramid number is:
Specs
p
is guaranteed to be larger than 2.- The program must check values for a solution for
p
up to (and including)2^16
. Your program may do anything if no solutions are found forp
. - Only positive indices for
n
.
Test cases
3
outputs10
(4th triangle number, 3rd triangle pyramid number)4
outputs4900
(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?
n
? If not, what is the range ofn
you'll be using? \$\endgroup\$n
-gonal andn
-gonal pyramid numbers shouldn't need defining. \$\endgroup\$