euler/python/e080.py

21 lines
440 B
Python
Raw Normal View History

from decimal import *
def euler_080():
# XXX: totally cheated by using decimal library.
def strsum(s):
return sum(map(int, s))
getcontext().prec = 200
r = 0
for n in range(1, 101):
b = str(Decimal(n).sqrt()).replace(".", "")[:100]
if len(b) == 100:
r += strsum(b)
return r
if __name__ == "__main__":
print("e080.py: " + str(euler_080()))
assert(euler_080() == 40886)