Skip to content

Instantly share code, notes, and snippets.

@cocodrips
Created March 30, 2015 17:50
Show Gist options
  • Save cocodrips/d7921202ba8d112714f3 to your computer and use it in GitHub Desktop.
Save cocodrips/d7921202ba8d112714f3 to your computer and use it in GitHub Desktop.
簡易版 平方根の小数点以下を求める
def sqrt(n, m):
a, b = 5 * n, 5
for i in xrange(m):
if a >= b:
a -= b
b += 10
else:
a *= 100
b = b * 10 - (b % 10 * 10) + (b % 10)
return b
print sqrt(2016, 1000) # 第二引数を大きくすると精度がさらによくなる
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment