def powers_1 (x, maxn):
    n = 1
    summ = 0
    c = 0
    while n <= maxn:
        summ = summ + n
        c = c + 1
        n = n * x
    return summ/c
    
def powers_2 (x, maxn, d):
    n = 1
    while n < maxn:
        if n%10 == d:
            return n
        n = n * x
    return -1
    
