mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-12-25 04:30:15 +00:00
1f8a21d727
* Tighten up psf/black and flake8 * Fix some tests * Fix some E741 * Fix some E741 * updating DIRECTORY.md Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
29 lines
501 B
Python
29 lines
501 B
Python
"""
|
|
2^15 = 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?
|
|
"""
|
|
|
|
|
|
def solution(power):
|
|
"""Returns the sum of the digits of the number 2^power.
|
|
|
|
>>> solution(1000)
|
|
1366
|
|
>>> solution(50)
|
|
76
|
|
>>> solution(20)
|
|
31
|
|
>>> solution(15)
|
|
26
|
|
"""
|
|
n = 2 ** power
|
|
r = 0
|
|
while n:
|
|
r, n = r + n % 10, n // 10
|
|
return r
|
|
|
|
|
|
if __name__ == "__main__":
|
|
print(solution(int(str(input()).strip())))
|