Difference between Sum of Cubes and Sum of First N Natural Numbers | Python3 program to find the difference between the sum of the cubes of the first N natural numbers and the sum of the first N natural number ; Sum of first n natural numbers ; Find the required difference ; Driver Code
def difference ( n ) : NEW_LINE INDENT S = ( n * ( n + 1 ) ) // 2 ; NEW_LINE res = S * ( S - 1 ) ; NEW_LINE return res ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT n = 5 ; NEW_LINE print ( difference ( n ) ) ; NEW_LINE DEDENT