OFFSET
2,1
COMMENTS
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.
The smallest prime(k) such that A238444(k) = n-2. - Vladimir Shevelev, Feb 28 2014
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
LINKS
MATHEMATICA
w[n_] := Block[{c = k = m = 1}, While[k < n, m = Mod[m *= k, n]; If[m == 1 || m + 1 == n, c++ ]; k++ ]; c]
PROG
(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
CROSSREFS
KEYWORD
hard,more,nonn
AUTHOR
Benoit Cloitre, Jun 03 2002
EXTENSIONS
2 more terms from Charles R Greathouse IV, Jan 24 2007
a(23) from Igor Naverniouk (igor(AT)cs.utoronto.ca), May 09 2007
STATUS
approved