也就是如何造开平方轮子咯?

翻翻 Wiki 先 -> Square Root
Methods of computing square roots

a=e(lna)/2=10(log10a)/2\sqrt{a} = e^{({ln \hspace{2mm} a)}/2} = 10^{({log_{10} \hspace{2mm} a)}/2}

那么实现就是:

import math
def isqrt(x):
return pow(10, math.log10(x)/2) #or pow(math.e, math.log(x)/2)

牛顿法的话是这样下面这样:

def isqrt(x):
x1 = x
while x1*x1 > x: #不对情况
x1 = (x1 + x/x1)
return x1

Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.