Repeated sum of first N natural numbers | Function to return the sum of the first n natural numbers ; Function to return the repeated sum ; Perform the operation exactly k times ; Update n with the sum of first n natural numbers ; Driver code
def sum ( n ) : NEW_LINE INDENT sum = ( n * ( n + 1 ) ) // 2 NEW_LINE return sum NEW_LINE DEDENT def repeatedSum ( n , k ) : NEW_LINE INDENT for i in range ( k ) : NEW_LINE INDENT n = sum ( n ) NEW_LINE DEDENT return n NEW_LINE DEDENT n = 2 NEW_LINE k = 2 NEW_LINE print ( repeatedSum ( n , k ) ) NEW_LINE