%I #24 Sep 26 2015 16:47:16
%S 2,3,5,7,17,67,137,23,61,71,401,1907,661,12227,29873,96731,99721,
%T 154243,480209,3408707,1738901,27341387
%N Highly Wilsonian primes: smallest primes p such that w(p)=n where w(n) denote the number of nonnegative integers k such that k! = +1 or -1 (mod n).
%C Obviously w(n) is at least 2 because 0! = 1! = +1 (mod n) for every n. Also, if p is a prime, then w(p) is at least 4 because (p-2)! = +1 and (p-1)! = -1 (mod p) by Wilson's Theorem.
%C The smallest prime(k) such that A238444(k) = n-2. - _Vladimir Shevelev_, Feb 28 2014
%C The sequence w(n) is 1, 2, 3, 2, 4, 2, 5, 2, 2, 2, 5, 2, 4,... (offset 1) = 1 +A049046(n) +A238532(n) for n>2. - _R. J. Mathar_, Apr 02 2014
%H K. S. Brown, <a href="http://www.mathpages.com/home/kmath029.htm">Highly Wilsonian Primes</a>
%H Igor Naverniouk, <a href="/A071710/a071710.cpp.txt">C++ program</a>
%t w[n_] := Block[{c = k = m = 1}, While[k < n, m = Mod[m *= k, n]; If[m == 1 || m + 1 == n, c++ ]; k++ ]; c]
%o (PARI) wilsonian(p)={ local(s,t,pMinusOne); pMinusOne=p-1; s=4; t=24; for(k=5,p-3, t=(t*k)%p; if(t==1 || t==pMinusOne, s=s+1) ); s } \\ _Charles R Greathouse IV_, Jan 24 2007
%K hard,more,nonn
%O 2,1
%A _Benoit Cloitre_, Jun 03 2002
%E 2 more terms from _Charles R Greathouse IV_, Jan 24 2007
%E a(23) from Igor Naverniouk (igor(AT)cs.utoronto.ca), May 09 2007