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

(added Ol)
Line 1,429:
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|Lua}}==
{{trans|C}}
<lang lua>function isqrt(x)
local q = 1
local r = 0
while q <= x do
q = q << 2
end
while q > 1 do
q = q >> 2
local t = x - r - q
r = r >> 1
if t >= 0 then
x = t
r = r + q
end
end
return r
end
 
print("Integer square root for numbers 0 to 65:")
for n=0,65 do
io.write(isqrt(n) .. ' ')
end
print()
print()
 
print("Integer square roots of oddd powers of 7 from 1 to 21:")
print(" n | 7 ^ n | isqrt(7 ^ n)")
local p = 7
local n = 1
while n <= 21 do
print(string.format("%2d | %18d | %12d", n, p, isqrt(p)))
----------------------
n = n + 2
p = p * 49
end</lang>
{{out}}
<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
 
Integer square roots of oddd powers of 7 from 1 to 21:
n | 7 ^ n | isqrt(7 ^ n)
3 | 343 | 18
5 | 16807 | 129
7 | 823543 | 907
9 | 40353607 | 6352
11 | 1977326743 | 44467
13 | 96889010407 | 311269
15 | 4747561509943 | 2178889
17 | 232630513987207 | 15252229
19 | 11398895185373143 | 106765608
21 | 558545864083284007 | 747359260</pre>
 
=={{header|MAD}}==
1,452

edits