Printing leftmost zeros . Since ( a ^ b ) % k can have digits less then k . In that case we need to print zeros
for ( int i = 0 ; i < k - Integer . toString ( temp ) . length ( ) ; i ++ ) System . out . print ( 0 ) ;