Big Integer Square Root

''Code taken from somewhere on the internet, modified somewhat. Returns the Square Root of the Big Integer using Newton-Raphson. Always returns an integer number, even if the square root is not an integer. The boolean didWork is true if A has an Integer Square Root.''

Java
static boolean didWork ; public static BigInteger sqrt(BigInteger A) { BigInteger temp = A.shiftRight(BigInteger.valueOf(A.bitLength).shiftRight(1).intValue), result = null; while (true) {        result = temp.add(A.divide(temp)).shiftRight(1); if (!temp.equals(result)) temp = result; else break ; }    didWork = false ; if (result.multiply(result).equals(A)) didWork = true ; return result; }

UVA Problems
10023 Square Root (Got A/C in Java; this algorithm is very fast. Read input as a String; watch for blank lines)