Counting equilateral triangles
InterviewTime limit1sMemory limit128 MB
Given a triangular tower with N layers of unit triangles, count every equilateral triangle of any size, both upward and downward pointing.
- Level
Medium4 of 10
- Topics
- Math, Combinatorics, Implementation, Brute force
- Solved
- No attempts yet
Problem
Small equilateral triangles of side length 1 are stacked into a triangular tower of layers. Count how many equilateral triangles, large and small together, the lines of that figure form. Triangles pointing up and triangles pointing down both count, and every side length from 1 small triangle up to small triangles counts.
When is 2, the answer is 5.

Input
The first line contains the layer count of the triangular tower. ()
Output
Print the total count of triangles, large and small together, on the first line.