Project Euler 56

Project Euler 56

题目

Powerful digit sum

A googol (\(10^{100}\)) is a massive number: one followed by one-hundred zeros; \(100^{100}\) 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, \(a^b\), where \(a, b < 100\), what is the maximum digital sum?

解决方案

使用Python直接计算\(a^b\)的值,并计算出数位的和。

代码

1
2
3
4
5
6
N = 100
ans = 0
for a in range(1, N):
for b in range(1, N):
ans = max(ans, sum(int(x) for x in str(a ** b)))
print(ans)
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
Ujimatsu Chiya 微信 微信
Ujimatsu Chiya 支付宝 支付宝