Java tutorial
//package com.java2s; import java.math.BigInteger; public class Main { public static BigInteger sqrt(final BigInteger val) { final BigInteger two = BigInteger.valueOf(2); BigInteger a = BigInteger.ONE.shiftLeft(val.bitLength() / 2); BigInteger b; do { b = val.divide(a); a = (a.add(b)).divide(two); } while (a.subtract(b).abs().compareTo(two) >= 0); return a; } }