By request, here's the SAS code I used:
proc optmodel;
/* declare parameters */
num n = 4;
set ROWS = 1..n;
set COLS = ROWS;
set CELLS = ROWS cross COLS;
set NEIGHBORHOOD {<i,j> in CELLS} = {<i2,j2> in CELLS: abs(i-i2) + abs(j-j2) <= 1};
/* construct primes */
num maxprime = 200;
set COMPOSITES = union {i in 3..sqrt(maxprime) by 2} i*i..maxprime by 2*i;
set PRIMES = {2} union (3..maxprime by 2 diff COMPOSITES);
put PRIMES=;
/* declare decision variables */
var NumMoves {CELLS} >= 0 integer;
var IsCellPrime {CELLS, PRIMES} binary;
/* declare objective */
min TotalNumMoves = sum {<i,j> in CELLS} NumMoves[i,j];
/* declare constraints */
con OnePrimePerCell {<i,j> in CELLS}:
sum {p in PRIMES} IsCellPrime[i,j,p] = 1;
con AtMostOneCellPerPrime {p in PRIMES}:
sum {<i,j> in CELLS} IsCellPrime[i,j,p] <= 1;
con Link {<i,j> in CELLS}:
sum {<i2,j2> in NEIGHBORHOOD[i,j]} NumMoves[i2,j2]
= sum {p in PRIMES} p * IsCellPrime[i,j,p];
/* call MILP solver */
solve;
/* print solution */
print NumMoves;
num sol {CELLS};
for {<i,j> in CELLS} do;
for {p in PRIMES: IsCellPrime[i,j,p].sol > 0.5} do;
sol[i,j] = p;
leave;
end;
end;
print sol;
quit;