Updated solution using log and floor functions to determine each a[i] exponent