user
Sometimes a function is needed to find the integer square root of   **X**,   where   **X**   can be a
real non─negative number.

Often   **X**   is actually a non─negative integer.

For the purposes of this task,   **X**   can be an integer or a real number,   but if it
simplifies things in your computer programming language,   assume it's an integer.

One of the most common uses of   **`Isqrt`**   is in the division of an integer by all factors   (or
primes)   up to the   
√ X     of that
integer,   either to find the factors of that integer,   or to determine primality.

An alternative method for finding the   **`Isqrt`**   of a number is to
calculate:        floor( sqrt(X) )

:   :   * where   **sqrt**    is the   square root   function for non─negative real numbers,   and
        * where   **floor**   is the   floor   function for real numbers.

If the hardware supports the computation of (real) square roots,   the above method might be a faster method for
small numbers that don't have very many significant (decimal) digits.

However, floating point arithmetic is limited in the number of   (binary or decimal)   digits that it can support.

Pseudo─code using quadratic residue

For this task, the integer square root of a non─negative number will be computed using a version
of   *quadratic residue*,   which has the advantage that no   *floating point*   calculations are
used,   only integer arithmetic.

Furthermore, the two divisions can be performed by bit shifting,   and the one multiplication can also be be performed by bit shifting or additions.

The disadvantage is the limitation of the size of the largest integer that a particular computer programming language can support.

Pseudo─code of a procedure for finding the integer square root of   **X**       (all variables are integers):

```
         q ◄── 1                                /*initialize  Q  to unity.  */
                                  /*find a power of 4 that's greater than X.*/
                  perform  while q <= x         /*perform while  Q <= X.    */
                  q ◄── q * 4                   /*multiply  Q  by  four.    */
                  end  /*perform*/
                                                /*Q  is now greater than  X.*/
         z ◄── x                                /*set  Z  to the value of X.*/
         r ◄── 0                                /*initialize  R  to zero.   */
                  perform  while q > 1          /*perform while  Q > unity. */
                  q ◄── q ÷ 4                   /*integer divide by  four.  */
                  t ◄── z - r - q               /*compute value of  T.      */
                  r ◄── r ÷ 2                   /*integer divide by  two.   */
                  if t >= 0  then do            
                                  z ◄── t       /*set  Z  to value of  T.   */
                                  r ◄── r + q   /*compute new value of  R.  */
                                  end
                  end  /*perform*/
                                                /*R  is now the  Isqrt(X).  */

         /* Sidenote: Also, Z is now the remainder after square root (i.e.  */
         /*           R^2 + Z = X, so if Z = 0 then X is a perfect square). */

```

Another version for the (above)   1st   **perform**   is:

```
                  perform  until q > X          /*perform until  Q > X.     */
                  q ◄── q * 4                   /*multiply  Q  by  four.    */
                  end  /*perform*/

```

Integer square roots of some values:

```
Isqrt( 0)  is   0               Isqrt(60)  is  7                Isqrt( 99)  is   9
Isqrt( 1)  is   1               Isqrt(61)  is  7                Isqrt(100)  is  10
Isqrt( 2)  is   1               Isqrt(62)  is  7                Isqrt(102)  is  10
Isqrt( 3)  is   1               Isqrt(63)  is  7
Isqrt( 4)  is   2               Isqrt(64)  is  8                Isqet(120)  is  10
Isqrt( 5)  is   2               Isqrt(65)  is  8                Isqrt(121)  is  11
Isqrt( 6)  is   2               Isqrt(66)  is  8                Isqrt(122)  is  11
Isqrt( 7)  is   2               Isqrt(67)  is  8
Isqrt( 8)  is   2               Isqrt(68)  is  8                Isqrt(143)  is  11
Isqrt( 9)  is   3               Isqrt(69)  is  8                Isqrt(144)  is  12
Isqrt(10)  is   3               Isqrt(70)  is  8                Isqrt(145)  is  12

```

Task

Compute and show all output here   (on this page)   for:

:   :   * the `Isqrt` of the     integers     from     **0** ───► **65**    (inclusive), shown in a horizontal format.
        * the `Isqrt` of the   odd powers  from   **71** ───► **773**   (inclusive), shown in a   vertical   format.
        * use commas in the displaying of larger numbers.

You can show more numbers for the 2nd requirement if the displays fits on one screen on Rosetta Code.
  
If your computer programming language only supports smaller integers,   show what you can.

Related tasks
:   * sequence of non-squares
    * integer roots
    * square root by hand
assistant
There is a task Integer roots that covers a similar operation, with the caveat that it will calculate **any** nth root (including 2) not just **square** roots.

See the Integer roots Raku entry.

Quadratic residue algorithm follows:

```
use Lingua::EN::Numbers;

sub isqrt ( \x ) { my ( $X, $q, $r, $t ) =  x, 1, 0 ;
    $q +<= 2 while $q ≤ $X ;
    while $q > 1 {
        $q +>= 2; $t = $X - $r - $q; $r +>= 1;
        if $t ≥ 0 { $X = $t; $r += $q }
    }
    $r
}

say (^66)».&{ isqrt $_ }.Str ;

(1, 3…73)».&{ "7**$_: " ~ comma(isqrt 7**$_) }».say

```

Output:

```
0 1 1 1 2 2 2 2 2 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 5 5 6 6 6 6 6 6 6 6 6 6 6 6 6 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 8 8
7**1: 2
7**3: 18
7**5: 129
7**7: 907
7**9: 6,352
7**11: 44,467
7**13: 311,269
7**15: 2,178,889
7**17: 15,252,229
7**19: 106,765,608
7**21: 747,359,260
7**23: 5,231,514,822
7**25: 36,620,603,758
7**27: 256,344,226,312
7**29: 1,794,409,584,184
7**31: 12,560,867,089,291
7**33: 87,926,069,625,040
7**35: 615,482,487,375,282
7**37: 4,308,377,411,626,977
7**39: 30,158,641,881,388,842
7**41: 211,110,493,169,721,897
7**43: 1,477,773,452,188,053,281
7**45: 10,344,414,165,316,372,973
7**47: 72,410,899,157,214,610,812
7**49: 506,876,294,100,502,275,687
7**51: 3,548,134,058,703,515,929,815
7**53: 24,836,938,410,924,611,508,707
7**55: 173,858,568,876,472,280,560,953
7**57: 1,217,009,982,135,305,963,926,677
7**59: 8,519,069,874,947,141,747,486,745
7**61: 59,633,489,124,629,992,232,407,216
7**63: 417,434,423,872,409,945,626,850,517
7**65: 2,922,040,967,106,869,619,387,953,625
7**67: 20,454,286,769,748,087,335,715,675,381
7**69: 143,180,007,388,236,611,350,009,727,669
7**71: 1,002,260,051,717,656,279,450,068,093,686
7**73: 7,015,820,362,023,593,956,150,476,655,802
```