Created
March 30, 2015 17:50
-
-
Save cocodrips/d7921202ba8d112714f3 to your computer and use it in GitHub Desktop.
簡易版 平方根の小数点以下を求める
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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