def distinct_powers(ceiling):
    """
    Returns the number of distinct terms in the sequence generated by a^b for
    2 <= a, b, <= ceiling.
    """
    powers = set()
    for a in range(2, ceiling + 1):
        for b in range(2, ceiling + 1):
            powers.add(a**b)
    return len(powers)