# What is the explicit formula for the sequence representing the number of any triangles in a triangular grid?

What is the explicit formula for the sequence representing the number of any triangles in a triangular grid, like those below?

### Context

• Counting only up-facing triangles of size one, we get triangular numbers.

• Counting both up-facing and down-facing triangles of size one, we get square numbers (that is, perfect squares)

But what is the total number of all triangles of any size? Here are some values for small $n$.

• I'd also like to know what you mean - do you mean those triangles pointing up (1,3,6,...)? Do you mean all of the smallest triangles (1,4,9,...)? Do you mean all the triangles of all sizes (1,5,13,...)? – user98602 Nov 20 '13 at 5:02
• @Mike: The latter. See my update. – kiss my armpit Nov 20 '13 at 5:11
• The accepted answer to the MSE post, how many triangles, by Brian M. Scott seems useful. He generalizes the particular question in that post. – J. W. Perry Nov 20 '13 at 5:36

The values fit $a_n=2n^2-2n+1$ To find that, two levels of differences gives a constant $4$, so the leading term is $(4/2!)n^2$. Subtract that off and you can find the rest.