Jump to content

Magic constant: Difference between revisions

add FreeBASIC
(add FreeBASIC)
Line 40:
 
=={{header|Basic}}==
==={{header|FreeBASIC}}===
<lang freebasic>
function a(byval n as uinteger) as ulongint
n+=2
return n*(n^2 + 1)/2
end function
 
function inv_a(x as double) as ulongint
dim as ulongint k = 0
while k*(k^2+1)/2+2 < x
k+=1
wend
return k
end function
 
dim as ulongint n
print "The first 20 magic constants are ":
for n = 1 to 20
print a(n);" ";
next n
print
print "The 1,000th magic constant is ";a(1000)
 
for e as uinteger = 1 to 20
print using "10^##: #########";e;inv_a(10^cast(double,e))
next e</lang>
{{out}}<pre>
The first 20 magic constants are
15 34 65 111 175 260 369 505 671 870 1105 1379 1695 2056 2465 2925 3439 4010 4641 5335
The 1,000th magic constant is 503006505
10^ 1: 3
10^ 2: 6
10^ 3: 13
10^ 4: 28
10^ 5: 59
10^ 6: 126
10^ 7: 272
10^ 8: 585
10^ 9: 1260
10^10: 2715
10^11: 5849
10^12: 12600
10^13: 27145
10^14: 58481
10^15: 125993
10^16: 271442
10^17: 584804
10^18: 1259922
10^19: 2714418
10^20: 5848036
</pre>
 
==={{header|QB64}}===
<lang qbasic>$NOPREFIX
781

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.