A centered polygonal number is a positive integer given by the number of vertices when a point is surrounded by (increasingly larger) polygons with the same number of sides, as shown below. For example, \$p_5(3) = 1 + 5 + 10 + 15 = 31\$ is a centered pentagonal number formed by taking a vertex and adding three layers of pentagons:
This question, however, concerns centerless polygonal numbers. In particular, we want to know how many ways we can write \$n\$ as the difference of two \$k\$-gonal numbers with \$k \geq 3\$—that is, a centered polygon with the center removed.
For example, \$35\$ can be written as the difference of two \$k\$-gonal numbers in five ways:
- \$p_5(4) - p_5(2) = 51 - 16\$,
- \$p_5(7) - p_5(6) = 141 - 106\$,
- \$p_7(3) - p_7(1) = 43 - 8\$,
- \$p_7(5) - p_7(4) = 106 - 71\$, and
- \$p_{35}(1) - p_{35}(0) = 36 - 1\$,
the first four of which are illustrated below:
The Challenge
This challenge will have you write a script that takes a positive integer n
and outputs the number of ways to write \$n\$ as a centerless polygonal number.
Since this is a code-golf challenge, the shortest code wins.
The sequence begins:
0, 0, 1, 1, 1, 2, 1, 2, 3, 2, 1, 5, 1, 2, 5, 3, 1, 6, 1, 5, 5, 2, 1, 8, 3, 2, 6, 5, 1, 10, 1, 4, 5, 2, 5, 12, 1, 2, 5, 8, 1, 10, 1, 5, 12, 2, 1, 11, 3, 6, 5, 5, 1, 12, 5, 8, 5, 2, 1, 19, 1, 2, 12, 5, 5, 10, 1, 5, 5, 10, 1, 18, 1, 2, 12, 5, 5, 10, 1, 11, 10, 2
This is now in the OEIS as A339010.
n=2
give 0? Isn't it the difference of triangular numbers 3 and 1? (Edit: Oops, I see the centered triangular numbers are a different sequence.) \$\endgroup\$