Jump to content

Magic constant: Difference between revisions

(Added Go)
Line 645:
10^20 5848036
</pre>
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<lang Mathematica>ClearAll[i, n, MagicSumHelper, MagicSum, InverseMagicSum]
MagicSumHelper[n_] = Sum[i, {i, n^2}]/n;
MagicSum[n_] := MagicSumHelper[n + 2]
InverseMagicSum[lim_] := Ceiling[-(1/(3^(1/3) (9 lim + Sqrt[3] Sqrt[1 + 27 lim^2])^(1/3))) + (9 lim + Sqrt[3] Sqrt[1 + 27 lim^2])^(1/3)/3^(2/3)]
 
MagicSum /@ Range[20]
MagicSum[1000]
 
exps = Range[1, 50];
nums = 10^exps;
Transpose[{Superscript[10, #] & /@ exps, InverseMagicSum[nums]}] // Grid</lang>
{{out}}
<pre>{15, 34, 65, 111, 175, 260, 369, 505, 671, 870, 1105, 1379, 1695, 2056, 2465, 2925, 3439, 4010, 4641, 5335}
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
10^21 12599211
10^22 27144177
10^23 58480355
10^24 125992105
10^25 271441762
10^26 584803548
10^27 1259921050
10^28 2714417617
10^29 5848035477
10^30 12599210499
10^31 27144176166
10^32 58480354765
10^33 125992104990
10^34 271441761660
10^35 584803547643
10^36 1259921049895
10^37 2714417616595
10^38 5848035476426
10^39 12599210498949
10^40 27144176165950
10^41 58480354764258
10^42 125992104989488
10^43 271441761659491
10^44 584803547642574
10^45 1259921049894874
10^46 2714417616594907
10^47 5848035476425733
10^48 12599210498948732
10^49 27144176165949066
10^50 58480354764257322</pre>
 
=={{header|Perl}}==
1,111

edits

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