Consider a triangle whose each side is divided into equal parts. The largest number of identical shapes will be among the smallest equal triangles. Let us count them.
Let us divide the triangle into horizontal strips, numbered from top to bottom.
In the last, -th (bottom) strip, there are triangles pointing upwards and n - 1 triangles pointing downwards.
In the penultimate, (n - 1)-th strip, there are n - 1 triangles pointing upwards and n - 2 triangles pointing downwards.
Continuing this reasoning, we obtain:
the number of triangles pointing upwards is n + (n - 1) + (n - 2) + ... + 2 + 1;
the number of triangles pointing downwards is (n - 1) + (n - 2) + ... + 2 + 1.
Thus, the total number of the smallest equal triangles is the sum of these two quantities:
Example
For n = 1, 2, and , the number of equal triangles is , and , respectively. For example, when n = 3, the answer is (1 + 2 + 3) + (1 + 2) = 9.
Algorithm implementation
Read the input value .
scanf("%lld",&n);Compute and print the answer.
res = n * n;
printf("%lld\n",res);Java implementation
import java.util.*;
class Main
{
public static void main(String[] args)
{
Scanner con = new Scanner(System.in);
long n = con.nextLong();
long res = n * n;
System.out.println(res);
con.close();
}
}Python implementation
Read the input value .
n = int(input())Compute and print the answer.
res = n * n
print(res)