Prime Magic Square

Author

Eric W. Weisstein
January 24, 2005

This notebook downloaded from http://mathworld.wolfram.com/notebooks/RecreationalMath/PrimeMagicSquare.nb.

For more information, see Eric's MathWorld entry http://mathworld.wolfram.com/PrimeMagicSquare.html.

©2005 Wolfram Research, Inc. except for portions noted otherwise

Examples

PrimeMagicSquares[3]:={
{{67,1,43},{13,37,61},{31,73,7}},
{{17,89,71},{113,59,5},{47,29,101}},
{{1669,199,1249},{619,1039,1459},{829,1879,409}}
}
PrimeMagicSquares[4]:={
{{3,61,19,37},{43,31,5,41},{7,11,73,29},{67,17,23,13}}
}

PrimeMagicSquares[12]:={
{{1,823,821,809,811,797,19,29,313,31,23,37},
		{89,83,211,79,641,631,619,709,617,53,43,739},
		{97,227,103,107,193,557,719,727,607,139,757,281},
		{223,653,499,197,109,113,563,479,173,761,587,157},
		{367,379,521,383,241,467,257,263,269,167,601,599},
		{349,359,353,647,389,331,317,311,409,307,293,449},
		{503,523,233,337,547,397,421,17,401,271,431,433},
		{229,491,373,487,461,251,443,463,137,439,457,283},
		{509,199,73,541,347,191,181,569,577,571,163,593},
		{661,101,643,239,691,701,127,131,179,613,277,151},
		{659,673,677,683,71,67,61,47,59,743,733,41},
		{827,3,7,5,13,11,787,769,773,419,149,751}}
}

PrimeMagicSquares[13]:={
{{1153,8923,1093,9127,1327,9277,1063,9133,9661,1693,991,8887,8353},
{9967,8161,3253,2857,6823,2143,4447,8821,8713,8317,3001,3271,907},
{1831,8167,4093,7561,3631,3457,7573,3907,7411,3967,7333,2707,9043},
{9907,7687,7237,6367,4597,4723,6577,4513,4831,6451,3637,3187,967},
{1723,7753,2347,4603,5527,4993,5641,6073,4951,6271,8527,3121,9151},
{9421,2293,6763,4663,4657,9007,1861,5443,6217,6211,4111,8581,1453},
{2011,2683,6871,6547,5227,1873,5437,9001,5647,4327,4003,8191,8863},
{9403,8761,3877,4783,5851,5431,9013,1867,5023,6091,6997,2113,1471},{1531,2137,7177,6673,5923,5881,5233,4801,5347,4201,3697,8737,9343},
{9643,2251,7027,4423,6277,6151,4297,6361,6043,4507,3847,8623,1231},
{1783,2311,3541,3313,7243,7417,3301,6967,3463,6907,6781,8563,9091},
{9787,7603,7621,8017,4051,8731,6427,2053,2161,2557,7873,2713,1087},
{2521,1951,9781,1747,9547,1597,9811,1741,1213,9181,9883,1987,9721}}
}

Table[MagicQ/@PrimeMagicSquares[n],{n,3,4}]

Table[MatrixForm/@PrimeQ[PrimeMagicSquares[n]],{n,3,4}]

Show[GraphicsArray[Flatten[Table[MagicSquarePlot[#,DisplayFunction->Identity]&/@PrimeMagicSquares[n],{n,3,4}]]]
]

Square 1

Smallest magic sum for a 3×3 prime square (with a 1)

Square 2

Smallest magic sum for a 3×3 prime square

Square 3

Smallest magic sum for a 3×3 prime square consisting of consecutive primes

-Subtract@@@Partition[Sort[Flatten[PrimeMagicSquares[3][[3]]]],2,1]

Square 4

Consecutive 3x3 (no 1 allowed)

MagicSquarePlot[cp1=
{{-12,-18,30},{42,0,-42},{-30,18,12}}+1480028171]

cp2=1480028000+{{159,153,201},{213,171,129},{141,189,183}};

cp1-cp2

MagicQ[cp1]

PrimeQ[cp1]

Prime/@Range@@{PrimePi[Min[#]],PrimePi[Max[#]]}&[Flatten[cp1]]==Sort[Flatten[cp1]]

Smallest Consecutive (including 1)

MagicQ[cp12]

MagicSquarePlot[cp12]

Prepend[Prime/@Range@@{PrimePi[Min[#]],PrimePi[Max[#]]}&[Rest[Flatten[cp12]]],1]==Sort[Flatten[cp12]]

Other

MagicSquarePlot[PrimeMagicSquares[13][[1]]]

MatrixForm/@(l=NestList[Take[#,{2,-2},{2,-2}]&,PrimeMagicSquares[13][[1]],5])

MagicQ/@l