Home Project Euler Teaching Projects Gallery

Problem 49: Self powers

The series, 11 + 22 + 33 + ... + 1010 = 10405071317.

Find the last ten digits of the series, 11 + 22 + 33 + ... + 10001000.


Algorthim:

Problem is pretty simple. The best way to go about is NOT to calculate the sum and find modular 10^10. The number is gigantic. It has at least 1001 digits!

So, what we can do is calculate a partial sum as we increment the self powers. And whenever the number is greater than 10^10, we only take the last 10 digits!

Code:

Result:

Answer: 9110846700
Runtime: 104 ms