%I #26 Jun 14 2018 17:53:52
%S 0,2,3,7,0,13,35,49,64,81,11,1,0,57,1,1,85,1,38,1,1,133,184,1,1,521,1,
%T 1,522,1,589,1,1,885,1,1,259,381,1,1,656,1,559,1,1,553,282,1,1,1,1,1,
%U 1802,1,1,1,1,2553,1593,1,3416,993,1,1,1,1,804
%N a(n) = ((n-1)! + 1) mod n^2.
%C By definition, when n > 1, a(n) = 0 then n is a Wilson prime (A007540).
%C For a(n) to equal 1, (n-1)! must be divisible by n^2 which is the prevailing case for large n. For example, all n which are a product of more than two distinct primes belong to this category. So do all proper powers of primes except 2^2, 2^3, and 3^2. Obviously, when a(n) = 1, then also A055976(n) = 1.
%C The cases of a(n) > 1 include, for example, all primes other than Wilson's and all numbers of the form n=2*p, where p is a prime.
%H Stanislav Sykora, <a href="/A301316/b301316.txt">Table of n, a(n) for n = 1..10000</a>
%H Wikipedia, <a href="https://en.wikipedia.org/wiki/Wilson_prime">Wilson prime</a>
%F a(n) = ((n-1)! + 1) mod n^2. - _Jon E. Schoenfield_, Mar 18 2018
%F a(n) = A038507(n-1) mod A000290(n). - _Michel Marcus_, Mar 20 2018
%e From _Muniru A Asiru_, Mar 20 2018: (Start)
%e ((1-1)! + 1) mod 1^2 = (0! +1) mod 1 = 2 mod 1 = 0.
%e ((2-1)! + 1) mod 2^2 = (1! +1) mod 4 = 2 mod 4 = 2.
%e ((3-1)! + 1) mod 3^2 = (2! +1) mod 9 = 3 mod 9 = 3.
%e ((4-1)! + 1) mod 4^2 = (3! +1) mod 16 = 7 mod 16 = 7.
%e ((5-1)! + 1) mod 5^2 = (4! +1) mod 25 = 25 mod 25 = 0.
%e ... (End)
%p seq((factorial(n-1)+1) mod n^2,n=1..60); # _Muniru A Asiru_, Mar 20 2018
%t Array[Mod[(# - 1)! + 1, #^2] &, 67] (* _Michael De Vlieger_, Apr 21 2018 *)
%o (PARI) a(n) = ((n-1)! + 1) % n^2; \\ _Michel Marcus_, Mar 18 2018
%o (GAP) List([1..60],n->(Factorial(n-1)+1) mod n^2); # _Muniru A Asiru_, Mar 20 2018
%Y Cf. A000290, A038507, A007540, A055976, A301317.
%K nonn
%O 1,2
%A _Stanislav Sykora_, Mar 18 2018