Magic constant: Difference between revisions
Content added Content deleted
m (add RPL) |
(→{{header|Mathematica}}/{{header|Wolfram Language}}: append Pascal) |
||
Line 877: | Line 877: | ||
10^49 27144176165949066 |
10^49 27144176165949066 |
||
10^50 58480354764257322</pre> |
10^50 58480354764257322</pre> |
||
=={{header|Pascal}}== |
|||
==={{header|Free Pascal}}=== |
|||
<syntaxhighlight lang="pascal"> |
|||
program MagicConst; |
|||
{$IFDEF FPC}{$MODE DELPHI}{$OPTIMIZATION ON,ALL}{$ENDIF} |
|||
{$IFDEF WINDOWS}{$APPTYPE CONSOLE}{$ENDIF} |
|||
function MagicSum(n :Uint32):Uint64; inline; |
|||
var |
|||
k : Uint64; |
|||
begin |
|||
k := n*Uint64(n); |
|||
result := (k*k+k) DIV 2; |
|||
end; |
|||
function MagSumPerRow(n:Uint32):Uint32; |
|||
begin |
|||
//result := MagicSum(n) DIV n; |
|||
//(n^3 + n) /2 |
|||
result := ((Uint64(n)*n+1)*n) DIV 2; |
|||
end; |
|||
var |
|||
s : String[31]; |
|||
i : Uint32; |
|||
lmt,rowcnt : extended; |
|||
Begin |
|||
writeln('First Magic constants 3..20'); |
|||
For i := 3 to 20 do |
|||
write(MagSumPerRow(i),' '); |
|||
writeln; |
|||
writeln('1000.th ',MagSumPerRow(1002)); |
|||
writeln('First Magic constants > 10^xx'); |
|||
//lmt = (rowcnt^3 + rowcnt) /2 -> rowcnt > (lmt*2 )^(1/3) |
|||
lmt := 2.0 * 10.0; |
|||
For i := 1 to 50 do |
|||
begin |
|||
rowcnt := Int(exp(ln(lmt)/3))+1.0;//+1 suffices |
|||
str(trunc(rowcnt),s); |
|||
writeln('10^',i:2,#9,s:18); |
|||
f := 10.0*lmt; |
|||
end; |
|||
end.</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
First Magic constants 3..20 |
|||
15 34 65 111 175 260 369 505 671 870 1105 1379 1695 2056 2465 2925 3439 4010 |
|||
1000.th 503006505 |
|||
First Magic constants > 1=0^xx |
|||
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 |
|||
... same as Mathematica |
|||
10^46 2714417616594907 |
|||
10^47 5848035476425733 |
|||
10^48 12599210498948732 |
|||
10^49 27144176165949066 |
|||
10^50 58480354764257322</pre> |
|||
=={{header|Perl}}== |
=={{header|Perl}}== |