Problem 80

completed January 9, 2012

Comments

I misread this problem at first. I didn’t know I needed to include the numbers to the left of the decimal point along with the ones on the right. I also spent a good amount of time dealing with string methods to try to get rid of the decimal.

Code

from decimal import *
getcontext().prec = 120

def digit_sum(n):
	n = str(n).replace('.', '')
	n = n[:100]
	total = 0
	for i in n:
		total += int(i)
	return total

totally = 0
print digit_sum(Decimal(2)**Decimal(.5))
for n in range(1, 101):
	root = Decimal(n)**Decimal(.5)
	if str(root)[-4:-1] != '000':
		totally += digit_sum(Decimal(n)**Decimal(.5))

print totally