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
def possible ( n ) : NEW_LINE INDENT if ( n > 3 ) : NEW_LINE INDENT sum = ( n * ( n + 1 ) ) // 2 ; NEW_LINE if ( sum % 3 == 0 ) : NEW_LINE INDENT return True ; NEW_LINE DEDENT DEDENT return False ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT n = 5 ; NEW_LINE if ( possible ( n ) ) : NEW_LINE INDENT print ( " Yes " ) ; NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) ; NEW_LINE DEDENT DEDENT