Given two integers N and K, the task is to find the sum of first N natural numbers then update N as the previously calculated sum. Repeat these steps K times and finally print the value of N.
Input: N = 2, K = 2
Operation 1: n = sum(n) = sum(2) = 1 + 2 = 3
Operation 2: n = sum(n) = sum(3) = 1 + 2 + 3 = 6
Input: N = 3, K = 2
Approach: Find the sum of first N natural numbers using the formula (N * (N + 1)) / 2 then update N with the calculated sum. Repeat these steps exactly K times and print the final value of N.
Below is the implementation of the above approach:
- Repeated subtraction among two numbers
- Squares of numbers with repeated single digits | Set 1 (3, 6 and 9)
- Total numbers with no repeated digits in a range
- Natural Numbers
- LCM of First n Natural Numbers
- Sum of first n natural numbers
- Sum of first N natural numbers which are divisible by X or Y
- Sum of squares of first n natural numbers
- Sum of all natural numbers in range L to R
- Sum of cubes of first n odd natural numbers
- Sum of first N natural numbers which are not powers of K
- Sum of all odd natural numbers in range L and R
- Sum of fifth powers of the first n natural numbers
- Sum of cubes of even and odd natural numbers
- Average of first n even 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 firstname.lastname@example.org. 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.