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
< ? php function kthdigit ( $ a , $ b , $ k ) { $ p = pow ( $ a , $ b ) ; $ count = 0 ; while ( $ p > 0 and $ count < $ k ) { $ rem = $ p % 10 ; $ count ++ ; if ( $ count == $ k ) return $ rem ; $ p = $ p / 10 ; } return 0 ; } $ a = 5 ; $ b = 2 ; $ k = 1 ; echo kthdigit ( $ a , $ b , $ k ) ; ? >