```\nfunction sqrt(uint256 a) internal pure returns (uint256) {\n      if (a == 0) {\n          return 0;\n      }\n\n      // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.\n      //\n      // We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have\n      // `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.\n      //\n      // This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`\n      // → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`\n      // → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`\n      //\n      // Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.\n      uint256 result = 1 << (log2(a) >> 1);\n\n      // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,\n      // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at\n      // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision\n      // into the expected uint128 result.\n      unchecked {\n          result = (result + a / result) >> 1;\n          result = (result + a / result) >> 1;\n          result = (result + a / result) >> 1;\n          result = (result + a / result) >> 1;\n          result = (result + a / result) >> 1;\n          result = (result + a / result) >> 1;\n          result = (result + a / result) >> 1;\n          return min(result, a / result);\n      }\n  }\n\n\n```\n