PE其他解题报告请参考这里,本题答案在留言首条
Powerful digit sum
Problem 56
A googol ( 1 0 100 10^{100} 10100) is a massive number: one followed by one-hundred zeros; 10 0 100 100^{100} 100100 is almost unimaginably large: one followed by two-hundred zeros. Despite their size, the sum of the digits in each number is only 1.
Considering natural numbers of the form, ab, where a, b < 100, what is the maximum digital sum?
题意:
让你求在范围内,最大的数位和
分析:
无
参考代码
def f(a, b):
c = pow(a, b)
sum = 0
for i in range(len(str(c))):
sum += int(str(c)[i])
return sum
res = -1
for i in range(100):
for j in range(100):
res = max(res, f(i, j))
print(res)
阅读好习惯:点赞 + 收藏~