Saturday, September 14, 2013

Problem 16 - Power Digit Sum

215 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26.
What is the sum of the digits of the number 21000?
_________________________________________________________________________________

def sumd(n):
 j=0
 i=10
 while 10*n>i:
  if n%i >= i/10:
   j= j + first(n-(n/i)*i)
  else:
   j=j
  i=10*i
 return j

def first(n):
 j=1
 i=1
 while n > i:
  j=n/i
  i = 10*i
 return j 

print sumd(2**1000)

No comments:

Post a Comment