Python练习题 044:Project Euler 016:乘方结果各个数值之和

本题来自 Project Euler 第16题:https://projecteuler.net/problem=16

'''
Project Euler 16: Power digit sum
2**15 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26.
What is the sum of the digits of the number 2**1000?

Answer: 1366
'''

print(sum(int(i) for i in str(2**1000)))

送分题又来了。一行代码搞定!思路:先计算出 2**1000,转为字符串,取出每个字符,转为数值,求和。搞定。

原文地址:https://www.cnblogs.com/iderek/p/6021828.html