Divide first N natural numbers into 3 equal sum subsets | Function that returns true if the subsets are possible ; If n <= 3 then it is not possible to divide the elements in three subsets satisfying the given conditions ; Sum of all the elements in the range [ 1 , n ] ; If the sum is divisible by 3 then it is possible ; Driver code
function possible ( n ) { if ( n > 3 ) { let sum = parseInt ( ( n * ( n + 1 ) ) / 2 ) ; if ( sum % 3 == 0 ) { return true ; } } return false ; } let n = 5 ; if ( possible ( n ) ) document . write ( " " ) ; else document . write ( " " ) ;