Check whether a number can be represented as sum of K distinct positive integers | Function that returns true if n can be represented as the sum of exactly k distinct positive integers ; If n can be represented as 1 + 2 + 3 + ... + ( k - 1 ) + ( k + x ) ; Driver code
def solve ( n , k ) : NEW_LINE INDENT if ( n >= ( k * ( k + 1 ) ) // 2 ) : NEW_LINE INDENT return True NEW_LINE DEDENT return False NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n = 12 NEW_LINE k = 4 NEW_LINE if ( solve ( n , k ) ) : NEW_LINE INDENT print ( " Yes " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) NEW_LINE DEDENT DEDENT