Count of ways to write N as a sum of three numbers | Java program to count the total number of ways to write N as a sum of three numbers ; Function to find the number of ways ; Check if number is less than 2 ; Calculate the sum ; Driver code
class GFG { static void countWays ( int n ) { if ( n <= 2 ) { System . out . print ( " - 1" ) ; } else { int ans = ( n - 1 ) * ( n - 2 ) / 2 ; System . out . print ( ans ) ; } } public static void main ( String [ ] args ) { int N = 5 ; countWays ( N ) ; } }