2 to the 15th power = 32768, and the sum of the numbers (the sum of each digit) is 3 + 2 + 7 + 6 + 8 = 26.
In the same way, find the sum of 2 to the 1000th power. http://odz.sakura.ne.jp/projecteuler/index.php?cmd=read&page=Problem%2016
Practice using the map () function.
def main():
t = 2**1000
ans = sum(map(lambda x : int(x), str(t)))
print ans
Postscript: Mathematical approach (N is a number that represents a decimal number, in this question it is a decimal number)
def main2():
t = 2**1000
N = 10
ans = 0
while t:
(t, r) = (t//N, t%N)
ans += r
print ans
Recommended Posts