computes power a^n in O(log n) mults