Sum of quotients of division of N by powers of K not exceeding N | Function to calculate sum of quotients obtained by dividing N by powers of K <= N ; Store the required sum ; Iterate until i exceeds N ; Update sum ; Multiply i by K to obtain next power of K ; Print the result ; Given N and K
function findSum ( N , K ) { var ans = 0 ; var i = 1 ; while ( i <= N ) { ans += Math . floor ( N / i ) ; i = i * K ; } document . write ( ans ) ; } var N = 10 , K = 2 ; findSum ( N , K ) ;