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

no edit summary
m (syntax highlighting fixup automation)
No edit summary
Line 2,132:
43 | 2,183,814,375,991,796,599,109,312,252,753,832,343 | 1,477,773,452,188,053,281
</pre>
 
 
=={{header|FreeBASIC}}==
Odd powers up to 7^21 are shown; more would require an arbitrary precision library that would just add bloat without being illustrative.
Line 2,188 ⟶ 2,190:
19 106,765,608
21 747,359,260</pre>
 
 
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">
include "NSLog.incl"
 
local fn IntSqrt( x as SInt64 ) as SInt64
SInt64 q = 1, z = x, r = 0, t
do
q = q * 4
until ( q > x )
while( q > 1 )
q = q / 4 : t = z - r - q : r = r / 2
if ( t > -1 ) then z = t : r = r + q
wend
end fn = r
 
SInt64 p
NSInteger n
CFNumberRef tempNum
CFStringRef tempStr
 
NSLog( @"Integer square root for numbers 0 to 65:" )
 
for n = 0 to 65
NSLog( @"%lld \b", fn IntSqrt( n ) )
next
NSLog( @"\n" )
 
NSLog( @"Integer square roots of odd powers of 7 from 1 to 21:" )
NSLog( @" n | 7 ^ n | fn IntSqrt(7 ^ n)" )
p = 7
for n = 1 to 21 step 2
tempNum = fn NumberWithLongLong( fn IntSqrt(p) )
tempStr = fn NumberDescriptionWithLocale( tempNum, fn LocaleCurrent )
NSLog( @"%2d | %18lld | %12s", n, p, fn StringUTF8String( tempStr ) )
p = p * 49
next
 
HandleEvents
</syntaxhighlight>
{{output}}
<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 odd powers of 7 from 1 to 21:
n | 7 ^ n | fn IntSqrt(7 ^ n)
1 | 7 | 2
3 | 343 | 18
5 | 16807 | 129
7 | 823543 | 907
9 | 40353607 | 6,352
11 | 1977326743 | 44,467
13 | 96889010407 | 311,269
15 | 4747561509943 | 2,178,889
17 | 232630513987207 | 15,252,229
19 | 11398895185373143 | 106,765,608
21 | 558545864083284007 | 747,359,260
</pre>
 
 
=={{header|Go}}==
717

edits