您的位置:首页 > 其它

Project Euler Problem 16

2015-08-13 18:01 288 查看
原题:

215 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26.

What is the sum of the digits of the number 21000?

由于2的1000次方是一个很大的数,远远超出范围,也因此一直没有好办法解这个题,最近看python,发现python对这个没有限制

(刚刚看的一点python内容,立马就用,不喜勿喷啊,不过发现python真的很强大,几行代码就搞定)

以下是python的代码:

# Project Euler 16
sum1 = 0
x = 2**1000
y = str(x)
for i in y:
sum1 = sum1+int(i)
print sum1

#The result is 1366
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: