代码拉取完成,页面将自动刷新
"""
Problem 56: https://projecteuler.net/problem=56
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?
"""
# _*_ conding:UTF-8 _*_
'''
@author = Kuperain
@email = kuperain@aliyun.com
@IDE = VSCODE Python3.8.3
@creat_time = 2022/5/18
'''
def solution(alimit: int = 100,blimit:int =100) -> int:
maxdigit = 0
res_a = 1
res_b = 1
for a in range(1,alimit):
for b in range(1,blimit):
n = a**b
sumofdigits = sum(map(int,str(n)))
if sumofdigits>maxdigit:
maxdigit = sumofdigits
res_a = a
res_b = b
print(f'{res_a}^{res_b}, the sum of digits is {maxdigit}.')
return maxdigit
if __name__ == "__main__":
import doctest
doctest.testmod(verbose=False)
print(solution())
# 972
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。