[Python] 16 – Power digit sum

[문제 링크]
http://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?

[소스 코드]

#python PowerDigitSum.py

input = input("number = ")
count = 1000
sum = 1;
for i in range(1, count+1):
    sum = sum * int(input)
str = str(sum)
print("Sum=", sum)

digitSum = 0
for j in range(0, len(str)):
    # print(str[j])
    digitSum = digitSum + int(str[j])
print("Digitsum=", digitSum)
print("Done")

[결과]
number = 2
Sum= 107150860718626732094842504906000181056140481170553360744375038837035105112
49361224931983788156958581275946729175531468251871452856923140435984577574698574
80393456777482423098542107460506237114187795418215304647498358194126739876755916
5543946077062914571196477686542167660429831652624386837205668069376
Digitsum= 1366
Done

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s