## Project Euler 119: Investigating the numbers which are equal to sum of their digits raised to some power

#### Problem Description

The number 512 is interesting because it is equal to the sum of its digits raised to some power: 5 + 1 + 2 = 8, and 8^{3} = 512. Another example of a number with this property is 614656 = 28^{4}.

We shall define *a*_{n} to be the *n*th term of this sequence and insist that a number must contain at least two digits to have a sum.

You are given that *a*_{2} = 512 and *a*_{10} = 614656.

Find *a*_{30}.

#### Analysis

Taking advantage of the easy large integer support in Python, we iterated two loops representing the base and exponent with the intention of accommodating inquiries up to *a*_{200}. Ignoring a^{b} values < 10 it was a simple process of adding the digits of the powers and comparing that sum to the base. After collecting relevant values into an array, it was sorted and the proper index printed for the answer.

#### Project Euler 119 Solution

Runs < 0.006 seconds in Python 2.7.Use this link to get the Project Euler 119 Solution Python 2.7 source.

#### Afterthoughts

- The base index of arrays in Python begin with 0. We need to subtract one from our index because the problem is using a base of 1;
*a*_{30}= a[29].

*Project Euler 119 Solution last updated*

a30 in base 10 is 63^8=248155780267521

why have you used n*1.1?

Hi Ankit,

It wasn’t needed. It was a way to early terminate the loops with a 10% over calculation because the generated numbers are not in order, so you have to calculate past the first 30 numbers to make sure your have your target index after sorting. 10% was just a guess.