login
a(n) = (n-2)! - 1 (mod n).
2

%I #8 Sep 14 2017 09:29:13

%S 0,0,1,0,-1,0,-1,-1,-1,0,-1,0,-1,-1,-1,0,-1,0,-1,-1,-1,0,-1,-1,-1,-1,

%T -1,0,-1,0,-1,-1,-1,-1,-1,0,-1,-1,-1,0,-1,0,-1,-1,-1,0,-1,-1,-1,-1,-1,

%U 0,-1,-1,-1,-1,-1,0,-1,0,-1,-1,-1,-1,-1,0,-1,-1,-1,0,-1,0,-1,-1,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,-1,-1,0,-1,-1,-1,-1

%N a(n) = (n-2)! - 1 (mod n).

%C (n-2)! - 1 is congruent to 0 iff n is a prime and is congruent to -1 iff n is a composite > 4.

%H Antti Karttunen, <a href="/A056051/b056051.txt">Table of n, a(n) for n = 2..10000</a>

%t Do[m = Mod[(n - 2)! - 1, n]; If[m < 2, Print[m], Print[m - n]], {n, 2, 100}]

%o (PARI) A056051(n) = { my(m=(((n-2)!-1)%n)); if(m < 2,m,m-n); }; \\ _Antti Karttunen_, Sep 14 2017, after Mathematica-code.

%Y Cf. A005171.

%K easy,sign

%O 2,1

%A _Robert G. Wilson v_, Jul 25 2000