Form a number using corner digits of powers | Find next power by multiplying N with current power ; Store digits of Power one by one . ; Calculate carry . ; Store carry in Power array . ; Prints number formed by corner digits of powers of N . ; Storing N raised to power 0 ; Initializing empty result ; One by one compute next powers and add their corner digits . ; Call Function that store power in Power array . ; Store unit and last digits of power in res . ; Driver Code
function nextPower ( N , power ) { var carry = 0 ; for ( var i = 0 ; i < power . length ; i ++ ) { var prod = ( power [ i ] * N ) + carry ; power [ i ] = prod % 10 ; carry = parseInt ( prod / 10 ) ; } while ( carry >= 1 ) { power . push ( carry % 10 ) ; carry = parseInt ( carry / 10 ) ; } return power ; } function printPowerNumber ( X , N ) { var power = [ ] ; power . push ( 1 ) ; var res = [ ] ; for ( var i = 1 ; i <= X ; i ++ ) { power = nextPower ( N , power ) ; res . push ( power [ power . length - 1 ] ) ; res . push ( power [ 0 ] ) ; } for ( var i = 0 ; i < res . length ; i ++ ) document . write ( res [ i ] ) ; } var N = 19 , X = 4 ; printPowerNumber ( X , N ) ;