Problem 48
The series, 11 + 22 + 33 + ... + 1010 = 10405071317.
Find the last ten digits of the series, 11 + 22 + 33 + ... + 10001000.
使用math.pow进行pow(1000, 1000)时会弹出OverflowError: math range error错误,所以自己造了一个power函数。
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:])