Hello, I have tried to take the root of a BigInteger
with the method pow
, BigInteger
because I cannot find the method that performs the square root operation on the instances of this class.
BigInteger sqr = n.pow(0.5);
However the method pow
only BigInteger
receives integers. If there is a way or if the method to take the square root of a BigInteger
does exist, I would appreciate it if you could clarify it for me, thanks.
It is something very similar to a brute force attack. first we choose a starting point, in this case we use the properties of the binary system in such a way that the value of the bit of half of the total length is in the cases that have integer square root, for example:
then we just iterate, if x/a=a then a*a=x.
for example: 81
in binary it is 1010001, it has 7 digits, half would be 4, 1000 in decimal is 8.
we start the to iterate: