1 Star 0 Fork 0

阿坚/projecteuler

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
p056.py 1.05 KB
一键复制 编辑 原始数据 按行查看 历史
阿坚 提交于 2022-05-18 20:50 . 58
"""
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
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/kuperain/projecteuler.git
git@gitee.com:kuperain/projecteuler.git
kuperain
projecteuler
projecteuler
master

搜索帮助