Count of ways to write N as a sum of three numbers | C ++ 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
#include <bits/stdc++.h> NEW_LINE using namespace std ; void countWays ( int n ) { if ( n <= 2 ) cout << " - 1" ; else { int ans = ( n - 1 ) * ( n - 2 ) / 2 ; cout << ans ; } } int main ( ) { int N = 5 ; countWays ( N ) ; return 0 ; }