Enhanced power function, computes b^n in log n time.