def ala(x, n = 5): ss = 0 while x != 0: ss += (x % 10) ** n x /= 10 return ss total = 0 for i in xrange(1000000): if i == ala(i): print i total += i print '\n\n', total - 1