Problem 48

Problem 48

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

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

Will pop up when using math.pow be pow (1000, 1000) OverflowError: math range error error, so we built a power function.

def power(x, y):
    tot = 1
    for i in range(y):
        tot *= x
    return tot

tot = 0
for i in range(1, 1001):  # except zero
    p = power(i, i)
    tot += power(i, i)
print(str(tot)[-10:])

 

Guess you like

Origin www.cnblogs.com/noonjuan/p/10978063.html