Given two integer N and K, the task is to find the sum of all the numbers from the range [1, N] excluding those which are powers of K.
Input: N = 10, K = 3
2 + 4 + 5 + 6 + 7 + 8 + 10 = 42
1, 3 and 9 are excluded as they are powers of 3.
Input: N = 200, K = 30
Approach: Find the sum of the following series:
- pwrK: The sum of all the powers of K from [1, N] i.e. K0 + K1 + K2 + … + Kr such that Kr ≤ N
- sumAll: The sum of all the integers from the range [1, N] i.e. (N * (N + 1)) / 2.
The result will be sumAll – pwrK
Below is the implementation of the above approach:
- Find k numbers which are powers of 2 and have sum N | Set 1
- Sum of fifth powers of the first n natural numbers
- Sum of first N natural numbers which are not powers of K
- Print all integers that are sum of powers of two given numbers
- Sum of fourth powers of the first n natural numbers
- Sum of fourth powers of first n odd natural numbers
- Sum of first N natural numbers by taking powers of 2 as negative number
- Count numbers in a range having GCD of powers of prime factors equal to 1
- Count of numbers whose sum of increasing powers of digits is equal to the number itself
- Calculate sum of all integers from 1 to N, excluding perfect power of 2
- Queries for the minimum element in an array excluding the given index range
- Represent n as the sum of exactly k powers of two | Set 2
- Powers of 2 to required sum
- Finding powers of any number P in N!
- Representation of a number in powers of other
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.