Problem 16

Problem 16

pow(2, 15) = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26.
2的15次方等于32768,而这些数字(3+2+7+6+8)的和为26
What is the sum of the digits of the number pow(2, 1000)?
2的1000次方的位数之和为多少?
import math

power = math.pow(2, 1000)
sum_of_digits = 0
with open('power_of_two.txt', 'w') as f:
    print('%d' % power, file=f)
with open('power_of_two.txt') as f:
    for line in f:
        for c in line:
            try:
                sum_of_digits += int(c)
            except:
                pass

print(sum_of_digits)

 



posted @ 2019-06-02 11:18  no樂on  阅读(143)  评论(0编辑  收藏  举报