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


function isPrime(v)
	if v <= 1 then return False
	for i = 2 To int(sqr(v))
		if v % i = 0 then return False
	next i
	return True
end function
 
function isWilson(n, p)
	if p < n then return false
	prod = 1
	p2 = p*p #p^2
	for i = 1 to n-1
		prod = (prod*i) mod p2
	next i
	for i = 1 to p-n
		prod = (prod*i) mod p2
	next i
	prod = (p2 + prod - (-1)**n) mod p2
	if prod = 0 then return true else return false
end function
 
print " n:      Wilson primes"
print "----------------------"
for n = 1 to 11
	print n;" :  ";
	for p = 3 to 10499 step 2
		if isPrime(p) and isWilson(n, p) then print p; " ";
	next p
	print
next n
end