2의 1000 제곱을 한다음에 각자리를 더하는 문제입니다.
Power digit sum
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?
Code
1 2 3 4 5 6 | string = str ( 2 * * 1000 ) # 2의 1000제곱을 문자열로 변환해서 저장. i = 0 total = 0 for i in string: # for문으로 문자열을 하나씩 읽어옵니다. total = total + int (i) #문자를 int()로 숫자로 변환하고 합산을 합니다. print (total) |