Magic constant: Difference between revisions
Content added Content deleted
(Add Factor) |
(Add QB64) |
||
Line 38: | Line 38: | ||
=={{header|Basic}}== |
|||
==={{header|QB64}}=== |
|||
<lang qbasic>$NOPREFIX |
|||
DIM order AS INTEGER |
|||
DIM target AS INTEGER64 |
|||
PRINT "First 20 magic constants:" |
|||
FOR i = 3 TO 22 |
|||
PRINT USING "####, "; MagicSum(i); |
|||
IF i MOD 5 = 2 THEN PRINT |
|||
NEXT i |
|||
PRINT |
|||
PRINT USING "1000th magic constant: ##########,"; MagicSum(1002) |
|||
PRINT |
|||
PRINT "Smallest order magic square with a constant greater than:" |
|||
FOR i = 1 TO 13 |
|||
target = 10 ^ i |
|||
DO |
|||
order = order + 1 |
|||
LOOP UNTIL MagicSum(order) > target |
|||
PRINT USING "10^**: #####,"; i; order |
|||
order = order * 2 - 1 |
|||
NEXT i |
|||
FUNCTION MagicSum&& (n AS INTEGER) |
|||
MagicSum&& = (n * n + 1) / 2 * n |
|||
END FUNCTION</lang> |
|||
{{out}} |
|||
<pre> |
|||
First 20 magic constants: |
|||
15 34 65 111 175 |
|||
260 369 505 671 870 |
|||
1,105 1,379 1,695 2,056 2,465 |
|||
2,925 3,439 4,010 4,641 5,335 |
|||
1000th magic constant: 503,006,505 |
|||
Smallest order magic square with a constant greater than: |
|||
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: 1,260 |
|||
10^10: 2,715 |
|||
10^11: 5,849 |
|||
10^12: 12,600 |
|||
10^13: 27,145 |
|||
</pre> |
|||
=={{header|Factor}}== |
=={{header|Factor}}== |