Given two integers and , the task is to find the sum of all the numbers within the range [1, n] excluding the numbers which are positive powers of k i.e. the numbers k, k2, k3 and so on.
Input: n = 10, k = 3
1 + 2 + 4 + 5 + 6 + 7 + 8 + 10 = 43
3 and 9 are excluded as they are powers of 3
Input: n = 11, k = 2
- Store the sum of first natural numbers in a variable i.e. sum = (n * (n + 1)) / 2.
- Now for every positive power of which is less than , subtract it from the .
- Print the value of the variable in the end.
Below is the implementation of the above approach:
- Sum of fifth powers of the first n natural numbers
- Sum of fourth powers of first n odd natural numbers
- Sum of fourth powers of the first n natural numbers
- Sum of first N natural numbers by taking powers of 2 as negative number
- Find k numbers which are powers of 2 and have sum N | Set 1
- Print all integers that are sum of powers of two given numbers
- Find the sum of numbers from 1 to n excluding those which are powers of K
- Count of numbers whose sum of increasing powers of digits is equal to the number itself
- Count numbers in a range having GCD of powers of prime factors equal to 1
- Natural Numbers
- Sum of first n natural numbers
- LCM of First n Natural Numbers
- Sum of cubes of first n odd natural numbers
- Sum of first N natural numbers which are divisible by 2 and 7
- Sum of squares of 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 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.