Here's a link to the problem. Is there any way I could optimize/speed up this code, perhaps make it more Pythonic?
"""How many distinct terms are in the sequence
generated by a^b for 2 <= a <= 100
and 2 <= b <= 100?"""
import math
from timeit import default_timer as timer
def distinctPowers(a_max, b_max):
products = []
for a in range(2, a_max + 1):
for b in range(2, b_max + 1):
if a ** b not in products:
products.append(a ** b)
return len(products)
start = timer()
ans = distinctPowers(100, 100)
elapsed_time = (timer() - start) * 1000 # s --> ms
print "Found %r in %r ms." % (ans, elapsed_time)