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 ; Prthe result ; Driver Code ; Given N and K
def findSum ( N , K ) : NEW_LINE INDENT ans = 0 NEW_LINE i = 1 NEW_LINE while ( i <= N ) : NEW_LINE INDENT ans += N // i NEW_LINE i = i * K NEW_LINE DEDENT print ( ans ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT N , K = 10 , 2 NEW_LINE findSum ( N , K ) NEW_LINE DEDENT