擅长:python、mysql、java
<p><a href="http://blog.dreamshire.com/project-euler-80-solution/" rel="nofollow">http://blog.dreamshire.com/project-euler-80-solution/</a></p>
<blockquote>
<p>First, the 100 digits include digits to the right and left of the decimal.</p>
<p>Second, make sure to calculate more digits than are necessary to avoid rounding errors as it affects some of the numbers.</p>
</blockquote>
<pre><code>from decimal import Decimal, localcontext
def prob80():
total = 0
for x in range(1,100):
print x
with localcontext() as ctx:
ctx.prec = 105
if len(str(Decimal(x).sqrt())) == 1:
total+=0
else:
a = sum([int(i) for i in str(Decimal(x).sqrt())[2:101]])+int(str(Decimal(x).sqrt())[0])
total+=a
return total
print prob80()
</code></pre>