Magic constant: Difference between revisions
Used logarithm to avoid overflow in the stretch task.
(Created Nim solution.) |
(Used logarithm to avoid overflow in the stretch task.) |
||
Line 885:
n * (n * n + 1) div 2
func minOrder(
## Return the smallest order such as the magic constant is greater than "
result = int(exp((Ln2 + n.toFloat * Ln10) / 3)) + 1
const First = 3
Line 912 ⟶ 911:
echo "\nOrder of the smallest magic square whose constant is greater than:"
for n in 1..
let left = "10" & n.superscript & ':'
echo left.alignLeft(6), ($minOrder(
</syntaxhighlight>
{{out}}
<pre>First 20 magic constants:
15 34 65 111 175 260 369 505 671 870 1105 1379 1695 2056 2465 2925 3439 4010 4641 5335
Line 943 ⟶ 941:
10¹⁷: 584804
10¹⁸: 1259922
10¹⁹: 2714418
10²⁰: 5848036
</pre>
|