Euler Problem 48

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));
    }
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s