Maximum count of Equilateral Triangles that can be formed within given Equilateral Triangle | Java program for the above approach ; Function to find the number of equilateral triangle formed within another triangle ; Check for the valid condition ; Number of triangles having upward peak ; Number of inverted triangles ; Total no . of K sized triangle ; Driver Code ; Given N and K ; Function Call
import java . util . * ; class GFG { static int No_of_Triangle ( int N , int K ) { if ( N < K ) return - 1 ; else { int Tri_up = 0 ; Tri_up = ( ( N - K + 1 ) * ( N - K + 2 ) ) / 2 ; int Tri_down = 0 ; Tri_down = ( ( N - 2 * K + 1 ) * ( N - 2 * K + 2 ) ) / 2 ; return Tri_up + Tri_down ; } } public static void main ( String [ ] args ) { int N = 4 , K = 2 ; System . out . print ( No_of_Triangle ( N , K ) ) ; } }