login
a(n) = -1 if n is a square, 1 if n is not a square.
2

%I #37 Jan 13 2024 03:33:07

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

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

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

%N a(n) = -1 if n is a square, 1 if n is not a square.

%C Equivalently, a(n) is the sign of (-1)^[parity of number of divisors of n].

%H Antti Karttunen, <a href="/A158387/b158387.txt">Table of n, a(n) for n = 1..65537</a>

%H <a href="/index/Eu#epf">Index entries for sequences computed from exponents in factorization of n</a>.

%H <a href="/index/Di#divseq">Index to divisibility sequences</a>.

%F a(n) = (-1)^tau(n) = (-1)^A000005(n).

%F a(1) = -1, a(p) = 1, a(pq) = 1, a(pq...z) = 1, a(p^k) = (-1)^(k+1), for p, q, ..., z primes.

%F Sum_{k=1..n} a(k) ~ n - 2*sqrt(n). - _Amiram Eldar_, Jan 13 2024

%e a(12) = (-1)^6 = 1.

%t Array[1 - 2 Boole[OddQ@ DivisorSigma[0, #]] &, 100] (* _Michael De Vlieger_, Nov 03 2017 *)

%t Table[If[IntegerQ[Sqrt[n]],-1,1],{n,120}] (* _Harvey P. Dale_, Feb 17 2020 *)

%o (PARI) a(n) = (-1)^numdiv(n) \\ _Michel Marcus_, Jun 13 2013

%o (PARI) a(n)=(-1)^issquare(n) \\ _Charles R Greathouse IV_, Jun 13 2013

%o (PARI) first(n) = my(res = vector(n, i, -1)); for(i = 1, sqrtint(n), res[i^2] = 1); res \\ _David A. Corneth_, Nov 03 2017

%Y Cf. A000005, A010052.

%Y Cf. primes (A000040), pq = product of two distinct primes (A006881), pq...z = product of k (k > 2) distinct primes p, q, ..., z (A120944), p^k = prime powers (A000961(n) for n > 1), k = natural numbers (A000027).

%K sign,easy

%O 1,1

%A _Jaroslav Krizek_, Mar 17 2009

%E Description corrected by _David A. Corneth_, Nov 03 2017