%I #29 Jul 19 2024 21:38:40
%S 0,1,1,2,1,0,1,0,0,0,1,0,1,0,0,0,1,0,1,0,0,0,1,0,0,0,0,0,1,0,1,0,0,0,
%T 0,0,1,0,0,0,1,0,1,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,1,0,0,0,0,0,1,0,
%U 0,0,1,0,1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,1,0,1,0,0
%N a(n) = -(n-1)! mod n.
%C The following sequences all appear to have the same parity (with an extra zero term at the start of A010051): A010051, A061007, A035026, A069754, A071574. - _Jeremy Gardiner_, Aug 09 2002
%C In particular, this is identical to the isprime function A010051 except for a(4) = 2 instead of 0. This is equivalent to Wilson's theorem, (n-1)! == -1 (mod n) iff n is prime. If n = p*q with p, q > 1, then p, q < n-1 and (n-1)! will contain the two factors p and q, unless p = q = 2 (if p = q > 2 then also 2p < n-1, so there are indeed two factors p in (n-1)!), whence (n-1)! == 0 (mod n). - _M. F. Hasler_, Jul 19 2024
%H Antti Karttunen, <a href="/A061007/b061007.txt">Table of n, a(n) for n = 1..10000</a>
%F a(4) = 2, a(p) = 1 for p prime, a(n) = 0 otherwise. Apart from n = 4, a(n) = A010051(n) = A061006(n)/(n-1).
%e a(4) = 2 since -(4 - 1)! = -6 = 2 mod 4.
%e a(5) = 1 since -(5 - 1)! = -24 = 1 mod 5.
%e a(6) = 0 since -(6 - 1)! = -120 = 0 mod 6.
%t Table[Mod[-(n - 1)!, n], {n, 100}] (* _Alonso del Arte_, Mar 20 2014 *)
%o (PARI) A061007(n) = ((-((n-1)!))%n); \\ _Antti Karttunen_, Aug 27 2017
%o (PARI) apply( {A061007(n) = !(n-1)!%n}, [0..99]) \\ _M. F. Hasler_, Jul 19 2024
%o (Python)
%o from sympy import isprime
%o def A061007(n): return 2 if n == 4 else int(isprime(n)) # _Chai Wah Wu_, Mar 22 2023
%Y Positive for all but the first term of A046022.
%Y Cf. A000040 (the primes), A000142, A010051 (isprime function), A055976, A061006, A061008, A061009.
%K nonn,easy
%O 1,4
%A _Henry Bottomley_, Apr 12 2001