mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-07-05 01:09:40 +08:00
Rename Project Euler directories and other dependent changes (#3300)
* Rename all Project Euler directories: Reason: The change was done to maintain consistency throughout the directory and to keep all directories in sorted order. Due to the above change, some config files had to be modified: 'problem_22` -> `problem_022` * Update scripts to pad zeroes in PE directories
This commit is contained in:
30
project_euler/problem_016/sol2.py
Normal file
30
project_euler/problem_016/sol2.py
Normal file
@ -0,0 +1,30 @@
|
||||
"""
|
||||
Problem 16: https://projecteuler.net/problem=16
|
||||
|
||||
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: int = 1000) -> int:
|
||||
"""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())))
|
Reference in New Issue
Block a user