Forming triangles using points on a square | Java implementation of the above approach ; Function to return the count of possible triangles ; Driver code
class GFG { static int noOfTriangles ( int n ) { int y = 4 * n ; return ( ( y * ( y - 2 ) * ( y - 1 ) ) - ( 4 * n * ( n - 2 ) * ( n - 1 ) ) ) / 6 ; } public static void main ( String [ ] args ) { int n = 1 ; System . out . println ( noOfTriangles ( n ) ) ; } }