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


require "prime"
 
module Modulo
  refine Integer do
    def factorial_mod(m) = (1..self).inject(1){|prod, n| (prod *= n) % m }
  end
end
 
using Modulo
primes = Prime.each(11000).to_a
 
(1..11).each do |n| 
  res = primes.select do |pr|
    prpr = pr*pr
    ((n-1).factorial_mod(prpr) * (pr-n).factorial_mod(prpr) - (-1)**n) % (prpr) == 0
  end
  puts "#{n.to_s.rjust(2)}: #{res.inspect}"
end
 