human
Find the sum of numbers from 1 to n excluding those which are powers of K | Function to return the sum of all the powers of k from the range [ 1 , n ].
To store the sum of the series.
While current power of k <= n.
Add current power to the sum.
Next power of k.
Return the sum of the series.
Find to return the sum of the elements from the range [ 1 , n ] excluding those which are powers of k.
Sum of all the powers of k from [ 1 , n ].
Sum of all the elements from [ 1 , n ].
Return the required sum.
Driver code"
Solution in Python:
assistant
#Here is code to find the sum of numbers from 1 to n excluding those which are powers of K and the other steps required.
 def sumPowersK ( n , k ) :
	sum = 0 ; num = 1 ;
	while ( num <= n ) :
		sum += num ;
		num *= k ;
	return sum ;
def getSum ( n , k ) :
	pwrK = sumPowersK ( n , k ) ;
	sumAll = ( n * ( n + 1 ) ) / 2 ;
	return ( sumAll - pwrK ) ;
if __name__ == " _ _ main _ _ " :
	n = 10 ; k = 3 ;
	print ( getSum ( n , k ) ) ;