Isqrt (integer square root) of X: Difference between revisions

m
(→‎{{header|Tiny BASIC}}: Works with (Tom Pittman's) TinyBasic.)
m (→‎{{header|Wren}}: Minor tidy)
 
(24 intermediate revisions by 12 users not shown)
Line 440:
71| 1,004,525,211,269,079,039,999,221,534,496,697,502,180,541,686,174,722,466,474,743| 1,002,260,051,717,656,279,450,068,093,686
73|49,221,735,352,184,872,959,961,855,190,338,177,606,846,542,622,561,400,857,262,407| 7,015,820,362,023,593,956,150,476,655,802
</pre>
 
=={{header|ALGOL W}}==
Algol W integers are restricted to signed 32-bit, so only the roots of the powers of 7 up to 7^9 are shown (7^11 will fit in 32-bits but the smallest power of 4 higher than 7^11 will overflow).
<syntaxhighlight lang="algolw">
begin % Integer square roots by quadratic residue %
% returns the integer square root of x - x must be >= 0 %
integer procedure iSqrt ( integer value x ) ;
if x < 0 then begin assert x >= 0; 0 end
else if x < 2 then x
else begin
% x is greater than 1 %
integer q, r, t, z;
% find a power of 4 that's greater than x %
q := 1;
while q <= x do q := q * 4;
% find the root %
z := x;
r := 0;
while q > 1 do begin
q := q div 4;
t := z - r - q;
r := r div 2;
if t >= 0 then begin
z := t;
r := r + q
end if_t_ge_0
end while_q_gt_1 ;
r
end isqrt;
% writes n in 14 character positions with separator commas %
procedure writeonWithCommas ( integer value n ) ;
begin
string(10) decDigits;
string(14) r;
integer v, cPos, dCount;
decDigits := "0123456789";
v := abs n;
r := " ";
r( 13 // 1 ) := decDigits( v rem 10 // 1 );
v := v div 10;
cPos := 12;
dCount := 1;
while cPos > 0 and v > 0 do begin
r( cPos // 1 ) := decDigits( v rem 10 // 1 );
v := v div 10;
cPos := cPos - 1;
dCount := dCount + 1;
if v not = 0 and dCount = 3 then begin
r( cPos // 1 ) := ",";
cPos := cPos - 1;
dCount := 0
end if_v_ne_0_and_dCount_eq_3
end for_cPos;
r( cPos // 1 ) := if n < 0 then "-" else " ";
writeon( s_w := 0, r )
end writeonWithCommas ;
begin % task test cases %
integer prevI, prevR, root, p7;
write( "Integer square roots of 0..65 (values the same as the previous one not shown):" );
write();
prevR := prevI := -1;
for i := 0 until 65 do begin
root := iSqrt( i );
if root not = prevR then begin
prevR := root;
prevI := i;
writeon( i_w := 1, s_w := 0, " ", i, ":", root )
end
else if prevI = i - 1 then writeon( "..." );
end for_i ;
write();
% integer square roots of odd powers of 7 %
write( "Integer square roots of 7^n, odd n" );
write( " n| 7^n| isqrt(7^n)" );
write( " -+--------------+--------------" );
p7 := 7;
for p := 1 step 2 until 9 do begin
write( i_w := 2, s_w := 0, p );
writeon( s_w := 0, "|" ); writeonWithCommas( p7 );
writeon( s_w := 0, "|" ); writeonWithCommas( iSqrt( p7 ) );
p7 := p7 * 49
end for_p
end task_test_cases
end.
</syntaxhighlight>
{{out}}
<pre>
Integer square roots of 0..65 (values the same as the previous one not shown):
0:0 1:1... 4:2... 9:3... 16:4... 25:5... 36:6... 49:7... 64:8...
 
Integer square roots of 7^n, odd n
n| 7^n| isqrt(7^n)
-+--------------+--------------
1| 7| 2
3| 343| 18
5| 16,807| 129
7| 823,543| 907
9| 40,353,607| 6,352
</pre>
 
=={{header|ALGOL-M}}==
The approachcode presented here, follows the task description. But be warned: there is a bug lurking in the algorithm as presented. The statement q := q * 4 in the first while notloop will overflow the quadraticlimits residueof algorithmALGOL-M's integer data type (-16,383 to +16,383) for any value of x greater than 4095 and trigger worksan justendless fineloop. The output has been put into columnar form to avoid what would otherwise be an ugly mess on a typical 80 column display.
<syntaxhighlight lang="algol">
BEGIN
 
COMMENT
% RETURN INTEGER SQUARE ROOT OF N %
RETURN INTEGER SQUARE ROOT OF N USING QUADRATIC RESIDUE
INTEGER FUNCTION ISQRT(N);
ALGORITHM. WARNING: THE FUNCTION WILL FAIL FOR X GREATER
INTEGER N;
THAN 4095;
INTEGER FUNCTION ISQRT(X);
INTEGER X;
BEGIN
INTEGER R1Q, R2R, Z, T;
R1Q := N1;
R2WHILE :Q <= 1;X DO
Q := Q * 4; % WARNING! OVERFLOW YIELDS 0 %
WHILE R1 > R2 DO
Z := X;
R := 0;
WHILE Q > 1 DO
BEGIN
R1Q := (R1+R2)Q / 24;
R2T := NZ - R /- R1Q;
R := R / 2;
IF T >= 0 THEN
BEGIN
Z := T;
R := R + Q;
END;
END;
ISQRT := R1R;
END;
 
Line 493 ⟶ 604:
END
</syntaxhighlight>
An alternative to the quadratic residue approach will allow calculation of the integer square root for the full range of signed integer values supported by ALGOL-M. (The output is identical.)
But for those for whom only the quadratic residue algorithm will do, just substitute this for the ISQRT() function in the previous example. (The output is identical.) But be warned: there is a bug lurking in the algorithm as presented in the task description. The statement q := q * 4 in the first while loop will overflow the limits of ALGOL-M's integer data type (-16,383 to +16,383) for any value of x greater than 4095 and trigger an endless loop.
<syntaxhighlight lang="algol">
% RETURN INTEGER SQUARE ROOT OF N %
COMMENT
INTEGER FUNCTION ISQRT(N);
RETURN INTEGER SQUARE ROOT OF N USING QUADRATIC RESIDUE
INTEGER N;
ALGORITHM. WARNING: THE FUNCTION WILL FAIL FOR X GREATER
THAN 4095;
INTEGER FUNCTION ISQRT(X);
INTEGER X;
BEGIN
INTEGER QR1, R, Z, TR2;
QR1 := 1N;
WHILER2 Q <:= X DO1;
WHILE R1 > R2 DO
Q := Q * 4; % WARNING! OVERFLOW YIELDS 0 %
Z := X;
R := 0;
WHILE Q > 1 DO
BEGIN
Q R1 := Q(R1+R2) / 42;
T R2 := Z - RN -/ QR1;
R := R / 2;
IF T >= 0 THEN
BEGIN
Z := T;
R := R + Q;
END;
END;
ISQRT := RR1;
END;
</syntaxhighlight>
Line 1,155 ⟶ 1,254:
 
{{out}}
<pre style="font-size: 11px">
<pre>
Integer square root for numbers 0 to 65:
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
Line 1,391 ⟶ 1,490:
 
=={{header|COBOL}}==
 
The COBOL compiler used here is limited to 18-digit math, meaning 7^19 is the largest odd power of 7 that can be calculated.
 
<syntaxhighlight lang="cobol"> IDENTIFICATION DIVISION.
PROGRAM-ID. I-SQRT.
 
DATA DIVISION.
WORKING-STORAGE SECTION.
01 QUAD-RET-VARS.
03 X PIC 9(18).
03 Q PIC 9(18).
03 Z PIC 9(18).
03 T PIC S9(18).
03 R PIC 9(18).
 
01 TO-65-VARS.
03 ISQRT-N PIC 99.
03 DISP-LN PIC X(22) VALUE SPACES.
03 DISP-FMT PIC Z9.
03 PTR PIC 99 VALUE 1.
 
01 BIG-SQRT-VARS.
03 POW-7 PIC 9(18) VALUE 7.
03 POW-N PIC 99 VALUE 1.
03 POW-N-OUT PIC Z9.
03 POW-7-OUT PIC Z(10).
 
PROCEDURE DIVISION.
BEGIN.
PERFORM SQRTS-TO-65.
PERFORM BIG-SQRTS.
STOP RUN.
 
SQRTS-TO-65.
PERFORM DISP-SMALL-SQRT
VARYING ISQRT-N FROM 0 BY 1
UNTIL ISQRT-N IS GREATER THAN 65.
 
DISP-SMALL-SQRT.
MOVE ISQRT-N TO X.
PERFORM ISQRT.
MOVE R TO DISP-FMT.
STRING DISP-FMT DELIMITED BY SIZE INTO DISP-LN
WITH POINTER PTR.
IF PTR IS GREATER THAN 22,
DISPLAY DISP-LN,
MOVE 1 TO PTR.
 
BIG-SQRTS.
PERFORM BIG-SQRT 10 TIMES.
BIG-SQRT.
MOVE POW-7 TO X.
PERFORM ISQRT.
MOVE POW-N TO POW-N-OUT.
MOVE R TO POW-7-OUT.
DISPLAY "ISQRT(7^" POW-N-OUT ") = " POW-7-OUT.
ADD 2 TO POW-N.
MULTIPLY 49 BY POW-7.
 
ISQRT.
MOVE 1 TO Q.
PERFORM MUL-Q-BY-4 UNTIL Q IS GREATER THAN X.
MOVE X TO Z.
MOVE ZERO TO R.
PERFORM ISQRT-STEP UNTIL Q IS NOT GREATER THAN 1.
 
MUL-Q-BY-4.
MULTIPLY 4 BY Q.
 
ISQRT-STEP.
DIVIDE 4 INTO Q.
COMPUTE T = Z - R - Q.
DIVIDE 2 INTO R.
IF T IS NOT LESS THAN ZERO,
MOVE T TO Z,
ADD Q TO R.</syntaxhighlight>
{{out}}
<pre> 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
ISQRT(7^ 1) = 2
ISQRT(7^ 3) = 18
ISQRT(7^ 5) = 129
ISQRT(7^ 7) = 907
ISQRT(7^ 9) = 6352
ISQRT(7^11) = 44467
ISQRT(7^13) = 311269
ISQRT(7^15) = 2178889
ISQRT(7^17) = 15252229
ISQRT(7^19) = 106765608</pre>
 
 
=={{header|Common Lisp}}==
{{trans|Scheme}}
Line 1,599 ⟶ 1,795:
isqrt(7^10) = 16807
isqrt(7^11) = 44467</pre>
 
=={{header|Craft Basic}}==
<syntaxhighlight lang="basic">alert "integer square root of first 65 numbers:"
 
for n = 1 to 65
 
let x = n
gosub isqrt
print r
 
next n
 
alert "integer square root of odd powers of 7"
cls
cursor 1, 1
 
for n = 1 to 21 step 2
 
let x = 7 ^ n
gosub isqrt
print "isqrt of 7 ^ ", n, " = ", r
 
next n
 
end
 
sub isqrt
 
let q = 1
 
do
 
if q <= x then
 
let q = q * 4
 
endif
 
wait
 
loop q <= x
 
let r = 0
 
do
 
if q > 1 then
 
let q = q / 4
let t = x - r - q
let r = r / 2
 
if t >= 0 then
 
let x = t
let r = r + q
 
endif
 
endif
 
loop q > 1
 
let r = int(r)
 
return</syntaxhighlight>
{{out| Output}}<pre>integer square root of first 65 numbers:
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
 
integer square root of odd powers of 7:
isqrt of 7 ^ 1 = 2
isqrt of 7 ^ 3 = 18
isqrt of 7 ^ 5 = 129
isqrt of 7 ^ 7 = 907
isqrt of 7 ^ 9 = 6352</pre>
 
=={{header|D}}==
Line 1,790 ⟶ 2,061:
isqrt(7^ 9) = 6352
isqrt(7^10) = 16807</pre>
 
=={{header|EasyLang}}==
{{trans|Lua}}
<syntaxhighlight lang=easylang>
func isqrt x .
q = 1
while q <= x
q *= 4
.
while q > 1
q = q div 4
t = x - r - q
r = r div 2
if t >= 0
x = t
r = r + q
.
.
return r
.
print "Integer square roots from 0 to 65:"
for n = 0 to 65
write isqrt n & " "
.
print ""
print ""
print "Integer square roots of 7^n"
p = 7
n = 1
while n <= 21
print n & " " & isqrt p
n = n + 2
p = p * 49
.
</syntaxhighlight>
 
 
=={{header|F_Sharp|F#}}==
Line 2,040 ⟶ 2,347:
T = 0
DO WHILE (Q .LTLE. NUM)
Q = Q * 4
END DO
Line 2,132 ⟶ 2,439:
43 | 2,183,814,375,991,796,599,109,312,252,753,832,343 | 1,477,773,452,188,053,281
</pre>
 
 
=={{header|FreeBASIC}}==
Line 3,118 ⟶ 3,424:
19 | 11398895185373143 | 106765608
21 | 558545864083284007 | 747359260</pre>
 
=={{header|M2000 Interpreter}}==
Using various types up to 7^35
 
<syntaxhighlight lang="m2000 interpreter">
module integer_square_root (f=-2) {
function IntSqrt(x as long long) {
long long q=1, z=x, t, r
do q*=4&& : until (q>x)
while q>1&&
q|div 4&&:t=z-r-q:r|div 2&&
if t>-1&& then z=t:r+= q
end while
=r
}
long i
print #f, "The integer square root of integers from 0 to 65 are:"
for i=0 to 65
print #f, IntSqrt(i)+" ";
next
print #f
print #f, "Using Long Long Type"
print #f, "The integer square roots of powers of 7 from 7^1 up to 7^21 are:"
for i=1 to 21 step 2 {
print #f, "IntSqrt(7^"+i+")="+(IntSqrt(7&&^i))+" of 7^"+i+" ("+(7&&^I)+")"
}
print #f
function IntSqrt(x as decimal) {
decimal q=1, z=x, t, r
do q*=4 : until (q>x)
while q>1
q/=4:t=z-r-q:r/=2
if t>-1 then z=t:r+= q
end while
=r
}
print #f, "Using Decimal Type"
print #f, "The integer square roots of powers of 7 from 7^23 up to 7^33 are:"
decimal j,p
for i=23 to 33 step 2 {
p=1:for j=1 to i:p*=7@:next
print #f, "IntSqrt(7^"+i+")="+(IntSqrt(p))+" of 7^"+i+" ("+p+")"
}
print #f
function IntSqrt(x as double) {
double q=1, z=x, t, r
do q*=4 : until (q>x)
while q>1
q/=4:t=z-r-q:r/=2
if t>-1 then z=t:r+= q
end while
=r
}
print #f, "Using Double Type"
print #f, "The integer square roots of powers of 7 from 7^19 up to 7^35 are:"
for i=19 to 35 step 2 {
print #f, "IntSqrt(7^"+i+")="+(IntSqrt(7^i))+" of 7^"+i+" ("+(7^i)+")"
}
print #f
}
open "" for output as #f // f = -2 now, direct output to screen
integer_square_root
close #f
open "out.txt" for output as #f
integer_square_root f
close #f
win "notepad", dir$+"out.txt"
</syntaxhighlight>
{{out}}
<pre>
The integer square root of integers from 0 to 65 are:
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
Using Long Long Type
The integer square roots of powers of 7 from 7^1 up to 7^21 are:
IntSqrt(7^1)=2 of 7^1 (7)
IntSqrt(7^3)=18 of 7^3 (343)
IntSqrt(7^5)=129 of 7^5 (16807)
IntSqrt(7^7)=907 of 7^7 (823543)
IntSqrt(7^9)=6352 of 7^9 (40353607)
IntSqrt(7^11)=44467 of 7^11 (1977326743)
IntSqrt(7^13)=311269 of 7^13 (96889010407)
IntSqrt(7^15)=2178889 of 7^15 (4747561509943)
IntSqrt(7^17)=15252229 of 7^17 (232630513987207)
IntSqrt(7^19)=106765608 of 7^19 (11398895185373143)
IntSqrt(7^21)=747359260 of 7^21 (558545864083284007)
 
Using Decimal Type
The integer square roots of powers of 7 from 7^23 up to 7^33 are:
IntSqrt(7^23)=5231514822 of 7^23 (27368747340080916343)
IntSqrt(7^25)=36620603758 of 7^25 (1341068619663964900807)
IntSqrt(7^27)=256344226312 of 7^27 (65712362363534280139543)
IntSqrt(7^29)=1794409584184 of 7^29 (3219905755813179726837607)
IntSqrt(7^31)=12560867089291 of 7^31 (157775382034845806615042743)
IntSqrt(7^33)=87926069625040 of 7^33 (7730993719707444524137094407)
 
Using Double Type
The integer square roots of powers of 7 from 7^19 up to 7^35 are:
IntSqrt(7^19)=106765608 of 7^19 (1.13988951853731E+16)
IntSqrt(7^21)=747359260 of 7^21 (5.58545864083284E+17)
IntSqrt(7^23)=5231514822 of 7^23 (2.73687473400809E+19)
IntSqrt(7^25)=36620603758 of 7^25 (1.34106861966396E+21)
IntSqrt(7^27)=256344226312 of 7^27 (6.57123623635343E+22)
IntSqrt(7^29)=1794409584184 of 7^29 (3.21990575581318E+24)
IntSqrt(7^31)=12560867089291 of 7^31 (1.57775382034846E+26)
IntSqrt(7^33)=87926069625040 of 7^33 (7.73099371970744E+27)
IntSqrt(7^35)=615482487375282 of 7^35 (3.78818692265665E+29)
 
 
</pre>
 
=={{header|MAD}}==
Line 4,869 ⟶ 5,286:
{{out}}
Perfect squares are denoted with an asterisk.
<pre style="font-size: 11px">
<pre>
The integer square roots of integers from 0 to 65 are:
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
Line 5,201 ⟶ 5,618:
rot over + ]
again ]
nip swap ] is sqrt + ( n --> n n )
 
( sqrt+ returns the integer square root and remainder )
( i.e. isqrt+ of 28 is 5 remainder 3 as (5^2)+3 = 28 )
( To make it task compliant change the last line to )
( "nip nip ] is sqrt + ( n --> n )" )
 
66 times [ i^ sqrt+ drop echo sp ] cr cr
73 times
[ 7 i^ 1+ ** sqrt+ drop
number$ +commas 41 justify
echo$ cr
Line 5,504 ⟶ 5,921:
73 49,221,735,352,184,872,959,961,855,190,338,177,606,846,542,622,561,400,857,262,407 7,015,820,362,023,593,956,150,476,655,802
</pre>
=={{header|RPL}}==
Because RPL can only handle unsigned integers, a light change has been made in the proposed algorithm,
{{works with|Halcyon Calc|4.2.7}}
{| class="wikitable"
! RPL code
! Comment
|-
|
#1
'''WHILE''' DUP2 ≥ '''REPEAT'''
SL SL '''END'''
#0
'''WHILE''' OVER #1 > '''REPEAT'''
SWAP SR SR SWAP
DUP2 +
SWAP SR SWAP
'''IF''' 4 PICK SWAP DUP2 ≥ '''THEN'''
- 4 ROLL DROP ROT ROT
OVER +
'''ELSE''' DROP2 '''END'''
'''END''' ROT ROT DROP2
´'''ISQRT'''’ STO
|
'''ISQRT''' ''( #n -- #sqrt(n) )''
q ◄── 1
perform while q <= x
q ◄── q * 4
z ◄── x
r ◄── 0
perform while q > 1
q ◄── q ÷ 4
u ◄── r + q
r ◄── r ÷ 2
if z >= u then do
z ◄── z - u
r ◄── r + q
else remove u and copy of z from stack
end perform, clean stack
|}
{{in}}
<pre>
≪ { } 0 65 FOR n n R→B ISQRT B→R + NEXT ≫ EVAL
≪ {} #7 1 11 START DUP ISQRT ROT SWAP + SWAP 49 * NEXT DROP ≫ EVAL
</pre>
{{out}}
<pre>
2: { 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 }
1: { # 2d # 18d # 129d # 907d # 6352d # 44467d # 311269d # 2178889d # 15252229d # 106765608d # 747359260d }
</pre>
 
=={{header|Ruby}}==
Ruby already has [https://ruby-doc.org/core-2.7.0/Integer.html#method-c-sqrt Integer.sqrt], which results in the integer square root of a positive integer. It can be re-implemented as follows:
Line 5,717 ⟶ 6,189:
end
</syntaxhighlight>
An alternate version of isqrt() that can handle the full range of S-BASIC integer values (well, almost: it will fail for 32,767) looks like this.
<syntaxhighlight lang="basic">
function isqrt(x = integer) = integer
Line 5,731 ⟶ 6,203:
</syntaxhighlight>
{{out}}
The output for 7^5 will be shown only if the alternate version of the function is used.
<pre>
Integer square root of first 65 numbers
Line 5,743 ⟶ 6,216:
1 7 2
3 343 18
5 16807 129
</pre>
 
Line 5,844 ⟶ 6,318:
73 49,221,735,352,184,872,959,961,855,190,338,177,606,846,542,622,561,400,857,262,407 7,015,820,362,023,593,956,150,476,655,802</pre>
 
=={{header|Seed7SETL}}==
<syntaxhighlight lang="setl">program isqrt;
loop for i in [1..65] do
putchar(lpad(str isqrt(i), 5));
if i mod 13=0 then print(); end if;
end loop;
 
print();
{{incorrect|Seed7|<br><br>This Rosetta Code task is to use a &nbsp; ''quadratic residue'' &nbsp; algorithm for finding the integer square root.<br><br>The pseudo-code is shown in the task's preamble which does ''not'' use the language's built-in sqrt() function.<br><br>Please use the required pseudo-code as shown in the task's preamble.<br><br>}}
loop for p in [1, 3..73] do
sqrtp := isqrt(7 ** p);
print("sqrt(7^" + lpad(str p,2) + ") = " + lpad(str sqrtp, 32));
end loop;
 
proc isqrt(x);
q := 1;
loop while q<=x do
q *:= 4;
end loop;
z := x;
r := 0;
loop while q>1 do
q div:= 4;
t := z-r-q;
r div:= 2;
if t>=0 then
z := t;
r +:= q;
end if;
end loop;
return r;
end proc;
end program;</syntaxhighlight>
{{out}}
<pre> 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
 
sqrt(7^ 1) = 2
sqrt(7^ 3) = 18
sqrt(7^ 5) = 129
sqrt(7^ 7) = 907
sqrt(7^ 9) = 6352
sqrt(7^11) = 44467
sqrt(7^13) = 311269
sqrt(7^15) = 2178889
sqrt(7^17) = 15252229
sqrt(7^19) = 106765608
sqrt(7^21) = 747359260
sqrt(7^23) = 5231514822
sqrt(7^25) = 36620603758
sqrt(7^27) = 256344226312
sqrt(7^29) = 1794409584184
sqrt(7^31) = 12560867089291
sqrt(7^33) = 87926069625040
sqrt(7^35) = 615482487375282
sqrt(7^37) = 4308377411626977
sqrt(7^39) = 30158641881388842
sqrt(7^41) = 211110493169721897
sqrt(7^43) = 1477773452188053281
sqrt(7^45) = 10344414165316372973
sqrt(7^47) = 72410899157214610812
sqrt(7^49) = 506876294100502275687
sqrt(7^51) = 3548134058703515929815
sqrt(7^53) = 24836938410924611508707
sqrt(7^55) = 173858568876472280560953
sqrt(7^57) = 1217009982135305963926677
sqrt(7^59) = 8519069874947141747486745
sqrt(7^61) = 59633489124629992232407216
sqrt(7^63) = 417434423872409945626850517
sqrt(7^65) = 2922040967106869619387953625
sqrt(7^67) = 20454286769748087335715675381
sqrt(7^69) = 143180007388236611350009727669
sqrt(7^71) = 1002260051717656279450068093686
sqrt(7^73) = 7015820362023593956150476655802</pre>
 
=={{header|Seed7}}==
Seed7 has integer [https://seed7.sourceforge.net/libraries/integer.htm#sqrt(in_integer) sqrt()] and bigInteger [https://seed7.sourceforge.net/libraries/bigint.htm#sqrt(in_var_bigInteger) sqrt()] functions.
These functions could be used if an integer square root is needed.
But this task does not allow using the language's built-in sqrt() function.
Instead the ''quadratic residue'' algorithm for finding the integer square root must be used.
<syntaxhighlight lang="seed7">$ include "seed7_05.s7i";
include "bigint.s7i";
Line 5,860 ⟶ 6,413:
stri := stri[.. index] & "," & stri[succ(index) ..];
end for;
end func;
 
const func bigInteger: isqrt (in bigInteger: x) is func
result
var bigInteger: r is 0_;
local
var bigInteger: q is 1_;
var bigInteger: z is 0_;
var bigInteger: t is 0_;
begin
while q <= x do
q *:= 4_;
end while;
z := x;
while q > 1_ do
q := q mdiv 4_;
t := z - r - q;
r := r mdiv 2_;
if t >= 0_ then
z := t;
r +:= q;
end if;
end while;
end func;
 
Line 5,869 ⟶ 6,445:
writeln("The integer square roots of integers from 0 to 65 are:");
for number range 0 to 65 do
write(sqrtisqrt(bigInteger(number)) <& " ");
end for;
writeln("\n\nThe integer square roots of powers of 7 from 7**1 up to 7**73 are:");
Line 5,875 ⟶ 6,451:
writeln("----- --------------------------------------------------------------------------------- -----------------------------------------");
for number range 1 to 73 step 2 do
writeln(number lpad 2 <& commatize(pow7) lpad 85 <& commatize(sqrtisqrt(pow7)) lpad 42);
pow7 *:= pow7 * 49_;
end for;
end func;</syntaxhighlight>
Line 6,243 ⟶ 6,819:
 
{{out}}
<pre style="font-size: 11px">
<pre>
Integer square root for numbers 0 to 65:
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
Line 6,491 ⟶ 7,067:
71 | 1,004,525,211,269,079,039,999,221,534,496,697,502,180,541,686,174,722,466,474,743 | 1,002,260,051,717,656,279,450,068,093,686
73 | 49,221,735,352,184,872,959,961,855,190,338,177,606,846,542,622,561,400,857,262,407 | 7,015,820,362,023,593,956,150,476,655,802
</pre>
 
=={{header|VTL-2}}==
The ISQRT routine starts at line 2000. As VTL-2 only has unsigned 16-bit arithmetic, only the roots of 7^1, 7^3 and 7^5 are shown as 7^7 is too large.
<syntaxhighlight lang="vtl2">
1000 X=0
1010 #=2000
1020 $=32
1030 ?=R
1040 X=X+1
1050 #=X=33=0*1070
1060 ?=""
1070 #=X<66*1010
1080 P=1
1090 X=7
1100 #=2000
1110 ?=""
1120 ?="Root 7^";
1130 ?=P
1140 ?="(";
1150 ?=X
1160 ?=") = ";
1170 ?=R
1180 X=X*49
1190 P=P+2
1200 #=P<6*1100
1210 #=9999
2000 A=!
2010 Q=1
2020 #=X>Q=0*2050
2030 Q=Q*4
2040 #=2020
2050 Z=X
2060 R=0
2070 #=Q<2*A
2080 Q=Q/4
2090 T=Z-R-Q
2100 I=Z<(R+Q)
2110 R=R/2
2120 #=I*2070
2130 Z=T
2140 R=R+Q
2150 #=2070
</syntaxhighlight>
{{out}}
<pre>
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
Root 7^1(7) = 2
Root 7^3(343) = 18
Root 7^5(16807) = 129
</pre>
 
Line 6,496 ⟶ 7,123:
{{libheader|Wren-big}}
{{libheader|Wren-fmt}}
<syntaxhighlight lang="ecmascriptwren">import "./big" for BigInt
import "./fmt" for Fmt
 
var isqrt = Fn.new { |x|
9,482

edits