The series, 1
1 + 2 2 + 3 3 + … + 10 10 = 10405071317.Find the last ten digits of the series, 1
1 + 2 2 + 3 3 + … + 1000 1000 .
The BigInteger class makes this one a joke. I’m sure its gets harder going forward. So I won’t act too smug.
import java.math.*;
public class Euler48
{
public static void main(String[] args)
{
Euler48 e = new Euler48();
System.out.format(“Problem: %s\n”, e.getClass().getName());
System.out.format(“Answer = %s\n”, e.Problem());
}
public String Problem ()
{
BigInteger big = BigInteger.valueOf(0);
for (int i = 1; i <= 1000; i++)
big = big.add(BigInteger.valueOf(i).pow(i));
return String.valueOf(big.toString().substring(big.toString().length()-10));
}
}