Project Euler # 16 "Sum of Powers" in Python

Problem 16 "Sum of powers"

$ 2 ^ {15} = 32768 $, and the sum of the numbers (the sum of each digit) is $ 3 + 2 + 7 + 6 + 8 = 26 $. Similarly, find the finger sum of $ 2 ^ {1000} $.

Python


# n = 15
n = 1000
result = sum(map(int, str(2 ** n)))

print result
print result == 1366

result


1366
True

Recommended Posts

Project Euler # 16 "Sum of Powers" in Python
Project Euler # 10 "sum of prime numbers" in Python
Project Euler # 13 "Sum of Large Numbers" in Python
Project Euler # 6 "Difference in sum of squares" in Python
Project Euler # 17 "Number of Characters" in Python
Project Euler # 1 "Multiples of 3 and 5" in Python
Functional programming in Python Project Euler 1
Project Euler 10 "Sum of Prime Numbers"
Functional programming in Python Project Euler 3
Project Euler # 5 "Minimum Multiples" in Python
Functional programming in Python Project Euler 2
Project Euler # 15 "Lattice Path" in Python
Project Euler # 4 "Maximum Palindrome" in Python
Project Euler # 11 "Maximum Product in Grid" in Python
Project Euler # 7 "1000 1st prime number" in Python
Project Euler # 9 "Special Pythagorean Triple" in Python
Project Euler # 14 "Longest Collatz Sequence" in Python
Project Euler # 2 "Even Fibonacci Numbers" in Python
Implement sum in Python
Project Euler # 8 "Maximum Product in Number String" in Python
Project Euler # 12 "High Divisibility Triangular Number" in Python
Learn cumulative sum in Python
Equivalence of objects in Python
Implementation of quicksort in Python
What I learned by solving 30 questions of python Project Euler
Division of timedelta in Python 2.7 series
MySQL-automatic escape of parameters in python
Handling of JSON files in Python
Implementation of life game in Python
Create Python project documentation in Sphinx
Law of large numbers in python
Implementation of original sorting in Python
Project Euler 11 "Maximum product in grid"
Reversible scrambling of integers in Python
Project Euler 9 Retention of calculation results
Project Euler 37
Project Euler 7
Project Euler 31
Project Euler 4
Project Euler 38
Project Euler 17
Project Euler 26
Project Euler 8
Project Euler 23
Project Euler 22
Project Euler 19
Project Euler 50
Project Euler 42
Project Euler 33
Project Euler 32
Project Euler 43
Project Euler 35
Project Euler 36
Project Euler 24
Project Euler 46
Project Euler 45
Project Euler 6
Project Euler 44
Project Euler 39
Project Euler 40
Project Euler 49