What is the smallest possible constant of a 3×3 magic square containing nine distinct non-composite numbers only?
I think this problem relies a bit on the definition of a magic square and the word "small".
If a magic square elements are limited to the numbers 1, 2, 3, ..., n^2, then it is termed a "Normal" Magic Square.
The only solution (constant = 15) to the 3x3 for a Normal Magic Square are
8 1 6
3 5 7
4 9 2
(and its 7 rotations/reflections)
Additional squares may be generated by adding or multiplying the same constant to each term.
Composites, on the other hand, are all positive non-primes excluding 1. Clearly the Normal 3x3 is not made exclusively of non-composites.
Then we go for the entire set of 3x3s including the non-normal 3x3s.
All 3x3s with distinct integers are of the following form, as per Edouard Lucas:
For integers a,b,c, with 3c being the constant, these are of the form:
(-b+c) (a+b+c) (-a+c)
(-a+b+c) (c) (a-b+c)
(a+c) (-a-b+c) (b+c)
The normal solution has (a, b, c) = (-1, -3, 5), with constant = 15
So. with the broader definition, the terms now can become negative and the constant as well.
If a constant being small means absolute value small, then a good candidate is
constant = -3
17 -39 19
1 -1 -3
-21 37 -19
or the negative of this.
Here is a program and some results. The constant (row sum) is given first.
-60
-1 -59 0
-19 -20 -21
-40 19 -39
-57
-1 -57 1
-17 -19 -21
-39 19 -37
-45
3 -53 5
-13 -15 -17
-35 23 -33
-21
11 -45 13
-5 -7 -9
-27 31 -25
-3
17 -39 19
1 -1 -3
-21 37 -19
-60
-3 -57 0
-17 -20 -23
-40 17 -37
-54
-1 -55 2
-15 -18 -21
-38 19 -35
etc...
program ms
implicit none
integer a,b,c,j,con,ielt,flag,sign(3,9),term(9)
data sign/0,-1,1, 1,1,1, -1,0,1,
1 -1,1,1, 0,0,1, 1,-1,1,
2 1,0,1, -1,-1,1, 0,1,1/
do a=-20,20
do b=-20,20
do 1 c=-20,20
do ielt=1,9
term(ielt)=sign(1,ielt)*a+sign(2,ielt)*b+sign(3,ielt)*c
call not_comp(term(ielt),flag) if(flag.eq.0)go to 1
do j=1,ielt-1
if(term(ielt).eq.term(j))go to 1
enddo
enddo
con=3*c
print 3,con
3 format(/,i5)
print 2,term
2 format( 3(i4,3x))
1 enddo
enddo
enddo
end
subroutine not_comp(i,flag)
c Not composite means a positive integer not prime or 1
c Flag = 1 if true
implicit none
integer i,j,k,l,m,flag
flag=1
if (i.le.1)return
k=sqrt(1.*i)
do j=2,k
m=(1.*i)/(1.*j)
l=m*j
if(l.eq.i)go to 1
enddo
flag=1
return
1 flag=0
return
end
Edited on September 29, 2018, 7:41 pm