Given an integer N, find the absolute difference between sum of the cubes of first N natural numbers and the sum of first N natural numbers.
Input: N = 3 Output: 30 Sum of first three numbers is 3 + 2 + 1 = 6 Sum of Cube of first three numbers is = 1 + 8 + 27 = 36 Absolute difference = 36 - 6 = 30 Input: N = 5 Output: 210
- The sum of the cube of first N natural numbers, using the formula:
- The sum of first N numbers, using the formula:
- The absolute difference between both the sums is
Below is the implementation of the above approach:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Sum of cubes of even and odd natural numbers
- Sum of cubes of first n odd natural numbers
- Average of Cubes of first N natural numbers
- Sum of alternating sign cubes of first N Natural numbers
- Minimum value of K such that sum of cubes of first K natural number is greater than equal to N
- Possible two sets from first N natural numbers difference of sums as D
- Sum of series formed by difference between product and sum of N natural numbers
- Sum of cubes of first n even numbers
- Number of perfect cubes between two given numbers
- Numbers less than N that are perfect cubes and the sum of their digits reduced to a single digit is 1
- Check whether a number can be represented as difference of two consecutive cubes
- Fill the missing numbers in the array of N natural numbers such that arr[i] not equal to i
- LCM of First n Natural Numbers
- Natural Numbers
- Sum of first n natural numbers
- Sum of all natural numbers in range L to R
- Sum of first N natural numbers which are divisible by 2 and 7
- Repeated sum of first N natural numbers
- Sum of sum-series of first N Natural numbers
- Sum of fifth powers of the first n natural numbers
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.