Project Euler: Problem 48 – Self powers

Problem 48:

The series, 11 + 22 + 33 + … + 1010 = 10405071317.
 
Find the last ten digits of the series, 11 + 22 + 33 + … + 10001000.

Idea:

Straight forward problem thanks to the BigInteger class.

String answer = "";

BigInteger sum = BigInteger.ZERO;

for(int i = 1; i <= 1000; i++) {
   sum = sum.add(BigInteger.valueOf(i).pow(i));
}

answer = sum.toString();
answer = answer.substring(answer.length()-10);
Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *