Brute force
Using python's {} set comprehension we can create a set with all the terms generated by the sequence: \( a^b \). Since a set discards duplicate elements, the solution is the length of that set.
def distinct_powers(n=100):
return len({a ** b for a in range(2, n + 1) for b in range(2, n + 1)})