Project Euler 16

Project Euler 16

题目

Power digit sum

$2^{16} = 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}$?

解决方案

利用Python可以计算大数的性质,可以直接将$2^{1000}$本身计算出来。

然后通过一些方法将数位提取出来相加。

代码

1
2
3
N = 2 ** 1000
ans = sum(list(map(int, str(N))))
print(ans)
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
Ujimatsu Chiya 微信 微信
Ujimatsu Chiya 支付宝 支付宝