Algorithm 1:
Suppose the number to be opened is a, and if the root number A is represented by sqrt(a), then the root of ((sqrt (x)-sqrt(a/x)) 2 = 0 is sqrt(a).
freaky
sqrt(a)=(x+a/x)/2
So you just need to set an initial value equal to (x+a/x)/2, substitute it into the above formula to get a more approximate value, and then substitute it into it to get a more accurate value ... so you can finally get a sufficiently accurate value of (x+a/x)/2.
Such as: calculating sqrt(5)
Set the initial value to 2.
1)sqrt(5)=(2+5/2)/2=2.25
2)sqrt(5)=(2.25+5/2.25)/2 = 2.236 1 1 1
3)sqrt(5)=(2.236 1 1 1+5/2.236 1 1 1)/2 = 2.236068
The difference between the results of these three steps and that of sqrt(5) is less than 0.00 1.
Or you can use the dichotomy:
Let f (x) = x 2-a.
Then sqrt(a) is the root of f(x)=0.
You can find two positive values m, where n makes f (m)
According to the monotonicity of the function, sqrt(a) is in the interval (m, n).
Then calculate (m+n)/2, and calculate f ((m+n)/2). If it is greater than zero, sqrt(a) is within the interval (m, (m+n)/2).
If it is less than zero, it is between ((m+n)/2, n). If it is equal to zero, then (m+n)/2 is of course sqrt(a). By repeating this several times, the range of sqrt(a) can be gradually narrowed, and a value is randomly taken in the last sufficiently accurate interval, which is approximately equal to sqrt(a).