K | To compute k - th digit in a ^ b ; Computing a ^ b ; Getting last digit ; Increasing count by 1 ; If current number is required digit ; Remove last digit ; Driver code
function kthdigit ( a , b , k ) { let p = Math . pow ( a , b ) ; let count = 0 ; while ( p > 0 && count < k ) { let rem = p % 10 ; count ++ ; if ( count == k ) return rem ; p = p / 10 ; } return 0 ; } let a = 5 , b = 2 ; let k = 1 ; document . write ( kthdigit ( a , b , k ) ) ;