5

(Again copied verbatim from a September 2009 thread I made.)

A Primally Magic Square (PMS) is exactly like a traditional magic square with a change of criteria. Where a traditional magic square is one where the sum of each row, column, and both diagonals are some number, usually 15 (uses 1-9). By contrast, a PMS is one where all rows, columns, and both diagonals form a prime number. Note: if a number is prime either forward or back, it counts.

Example:

$\displaystyle \begin{matrix} 1 & 3 & 7 \\ 3 & 9 & 7 \\ 7 & 7 & 9 \end{matrix}$

137, 397, 977, 797, and 199 are all prime, so this square is a PMS.

How many 3x3 PMS's are there?

How many 4x4 PMS's are there?

How many 5x5 PMS's are there?

How many 9x9 PMS's are there?

Side note: Feel free to calculate the number of PMS's for some other $n$.

RobPratt
  • 50,938
  • Why are you not interested in 6x6 through 8x8 PMSs? And what about 2x2? – Matthew Conroy May 08 '11 at 20:58
  • Is it obvious that there is at least one PMS of each of those size? For 2 by 2 PMS, you can fill a square with ones for example. – Joel Cohen May 08 '11 at 21:30
  • @Matthew: Feel free to calculate those too. :P @Joel: Given the increasing number of primes as $n$ increases, I think there should be at least one PMS. – El'endia Starman May 08 '11 at 21:47
  • 1
    @ El'endia Starman : Doesn't the proportion of primes (among numbers with $n$ digits) decreases as $\frac{9}{n}$ asymptotically? – Joel Cohen May 08 '11 at 22:28
  • @Joel: Yes, but the absolute number of primes increases, so that should compensate for the increasing difficulty of making a PMS. – El'endia Starman May 08 '11 at 23:34
  • @ El'endia Starman: Have you tried writing a program to count them? This is absolutely doable for at least smaller $n$. – Matthew Conroy May 09 '11 at 02:24
  • @Matthew: Hmmm...good point. It HAS been about a year and a half and my programming skills have definitely improved in that time... :P – El'endia Starman May 09 '11 at 03:30
  • On reddit someone did a bruteforce search of the 3by3's here and a commenter found 2 4by4s here. – JSchlather May 18 '11 at 00:08
  • @Jacob: Nice links! Those are not quite what I'm going for here though; my condition is merely that each column, row, and diagonal needs to be prime in at least one direction, not both as they did. – El'endia Starman May 18 '11 at 00:20

2 Answers2

0

Following a comment, let's look at the $2×2$ case. I shall consider the case where all digits are distinct and to avoid issues with convention, nonzero.

Within these limits we select a set of four digits such as $\{1,2,3,4\}$. If each of the six two-element permutations generates a prime in either order, we have three primary magic squares apart from rotations and reflections (depending on which element is opposite a given one).

The set $\{1,2,3,4\}$ fails because $42$ and $24$ are both composite, and similarly there cannot be any two even digits, nor the digit $5$ (only two numbers in the 50s are prime and we would need three). We also cannot have two digits with residues $1,2\bmod 3$ or two multiples of $3$ (which lead to multiples of $3$), nor specifically $4$ together with $9$ (the odd number $49$ is $7×7$).

Here are the sets that work:

$\{1,3,4,7\}$

And that seems to be it! Thus three squares (plus trivial operations):

$\begin{array}&1&3\\4&7\end{array}$

$\begin{array}&1&4\\7&3\end{array}$

$\begin{array}&1&7\\3&4\end{array}$

Oscar Lanzi
  • 48,208
-2

I am quite late to answer this, but anyway: In general case there are a lot of solutions even for 2x2. Computer search gives 105 combinations(excluding variants that contain 0). I uploaded the list to github to save space here

Full list

For 3x3 there are 179979 solutions. For 4x4 the answer is 11156266908.

If we require the primes to be distinct it will be less, but still a lot. For 2x2 we have 24 solutions PMS list with distinct primes

For 3x3 the answer is 84080 in this case.

It will take many years to calculate all 5x5 PMS by brute-force search, and I am unaware of more efficient algorithm. So I stop at 4x4.

alex st
  • 187