def numsum(x): out = 0 while x > 0: out += x % 10 x /= 10 return out mmax = [0, 0, 0] for i in xrange(1, 101): for j in xrange(1, 101): tmp = numsum(i ** j) if tmp > mmax[0]: mmax = [tmp, i, j] print mmax