问题描述如下:
The series, 11 + 22 + 33 + … + 1010 = 10405071317.
Find the last ten digits of the series, 11 + 22 + 33 + … + 10001000.
即最后十位是什么。
Java code:
public class Problem48
{
public static void main(String[] args)
{
long start = System.currentTimeMillis();
BigInteger sum = BigInteger.ZERO;
for (int i = 1; i <= 1000; i++)
{
sum = sum.add(BigInteger.valueOf(i).pow(i));
}
String result = sum.toString();
System.err.println("sum = " + result.substring(result.length() - 10));
System.out.println(System.currentTimeMillis() - start);
}
}
result:
sum = 9110846700
142ms