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

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


In [1]:
def foo(n, m):
    return str(sum((i ** i for i in range(1, n + 1))))[-m:]

In [2]:
foo(10, 10)


Out[2]:
'0405071317'

In [3]:
n = 1000
m = 10
%timeit foo(n, m)
foo(n, m)


10 loops, best of 3: 72 ms per loop
Out[3]:
'9110846700'