Represent K ^ N as the sum of exactly N numbers | Function to print N numbers whose sum is a power of K ; Printing K ^ 1 ; Loop to print the difference of powers from K ^ 2 ; Driver code
function print ( n , k ) { document . write ( k + " " ) ; for ( var i = 2 ; i <= n ; i ++ ) { var x = Math . pow ( k , i ) - Math . pow ( k , i - 1 ) ; document . write ( x + " " ) ; } } var N = 3 , K = 4 ; print ( N , K ) ;