Definition
A Wilson prime of order n is a prime number   p   such that   p2   exactly divides:

     (n − 1)! × (p − n)! − (− 1)n 



If   n   is   1,   the latter formula reduces to the more familiar:   (p - n)! + 1   where the only known examples for   p   are   5,   13,   and   563.



Task
Calculate and show on this page the Wilson primes, if any, for orders n = 1 to 11 inclusive and for primes p < 18   or,

if your language supports big integers, for p < 11,000.



Related task
 Primality by Wilson's theorem


import strformat, strutils
import bignum
 
const Limit = 11_000
 
# Build list of primes using "nextPrime" function from "bignum".
var primes: seq[int]
var p = newInt(2)
while p < Limit:
  primes.add p.toInt
  p = p.nextPrime()
 
# Build list of factorials.
var facts: array[Limit, Int]
facts[0] = newInt(1)
for i in 1..<Limit:
  facts[i] = facts[i - 1] * i
 
var sign = 1
echo " n: Wilson primes"
echo "—————————————————"
for n in 1..11:
  sign = -sign
  var wilson: seq[int]
  for p in primes:
    if p < n: continue
    let f = facts[n - 1] * facts[p - n] - sign
    if f mod (p * p) == 0:
      wilson.add p
  echo &"{n:2}:  ", wilson.join(" ")