Given an equilateral triangle, the task is to compute the total number of triangles after performing the following operation N times.
For every operation, the uncolored triangles are taken and divided into 4 equal equilateral triangles. Every inverted triangle formed is colored. Refer to the below figure for more details.
For N=1 the triangle formed is:
For N=2 the triangle formed is:
Input :N = 10
Output : 118097
Input : N = 2
Output : 17
At every operation, 3 uncolored triangles, 1 colored triangle and the triangle itself is formed On writing the above statement mathematically; count of triangles at Nth move = 3 * count of triangles at (N-1)th move + 2 Therefore, initializing a variable curr = 1 and tri_count = 0 Next, a loop is iterated from 1 to N For every iteration, the operation mentioned above is performed. Finally, the tri_count is returned
Below is the implementation of the above approach:
- Count of triangles with total n points with m collinear
- Total number of triangles formed when there are H horizontal and V vertical lines
- Count the number of possible triangles
- Count number of unique Triangles using STL | Set 1 (Using set)
- Count number of right triangles possible with a given perimeter
- Count total number of digits from 1 to n
- Count total number of even sum sequences
- Count total number of N digit numbers such that the difference between sum of even and odd digits is 1
- Count the total number of squares that can be visited by Bishop in one move
- Count total set bits in all numbers from 1 to n | Set 2
- Count total divisors of A or B in a given range
- Number of triangles after N moves
- Number of triangles that can be formed
- Count total unset bits in all the numbers from 1 to N
- Count pairs from two arrays whose modulo operation yields K
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : 29AjayKumar