The following code throws me the error:
Traceback (most recent call last):
File \"\", line 25, in
sol = anna.main()
File \"\", line 17, in
It may not be your exact case, but if you want to take the square root of a large number AND you want to have control of the precision of the result, going either to math.sqrt()
or x ** 0.5
would not be much useful because your result will end up being a float number, and for large enough inputs, this will hit the limitations of float numbers.
One possibility for the specific case of sqrt
is to look into an integer-only implementation of the square root algorithm, e.g. flyingcircus.util.isqrt() (Disclaimer: I am the main author of flyingcircus).
Alternatively, for a more general solution, one may look into gmpy (or any other arbitrary precision library with Python bindings).