%I #41 Sep 21 2020 03:33:04
%S 1,1,1,-1,1,1,1,0,-1,1,1,-1,1,1,1,0,1,-1,1,-1,1,1,1,0,-1,1,0,-1,1,1,1,
%T 0,1,1,1,1,1,1,1,0,1,1,1,-1,-1,1,1,0,-1,-1,1,-1,1,0,1,0,1,1,1,-1,1,1,
%U -1,0,1,1,1,-1,1,1,1,0,1,1,-1,-1,1,1,1,0,0,1,1,-1,1,1,1,0,1,-1,1,-1,1,1,1,0,1,-1,-1,1
%N Apostol's second order Möbius (or Moebius) function mu_2(n).
%C The function mu_k(n) is defined to be 0 if a (k+1)st power of a prime divides n, otherwise it is (-1)^r where r is the number of distinct primes p that appear as p^k in the canonical factorization of n.
%C Differs from the (non-multiplicative) A053864 at n= 12, 18, 20, 28, 44, 45, 50, 52, 60, ... _R. J. Mathar_, Dec 17 2012
%H Antti Karttunen, <a href="/A189021/b189021.txt">Table of n, a(n) for n = 1..10000</a>
%H Tom Apostol, <a href="http://www.ams.org/mathscinet-getitem?mr=434929">Introduction to analytic number theory</a>, (1976) Springer, page 50
%H Tom Apostol, <a href="http://projecteuclid.org/euclid.pjm/1102977519">Mobius function of order k</a>, Pac. J. Math. 32 (1) (1970) 21-27
%H Antal Bege, <a href="http://arxiv.org/abs/0907.5293">A generalization of Apostol's Mobius functions of order k</a>, arXiv:0907.5293 [math.NT], 2009.
%H R. J. Mathar, <a href="http://arxiv.org/abs/1106.4038">Survey of Dirichlet series of multiplicative arithmetic functions</a>, arXiv:1106.4038 [math.NT], 2011-2012, Section 4.3.
%H A. F. Möbius, <a href="http://gdz.sub.uni-goettingen.de/dms/load/img/?PID=GDZPPN002138654">Über eine besondere Art von Umkehrung der Reihen.</a> Journal für die reine und angewandte Mathematik 9 (1832), 105-123.
%H <a href="/index/Eu#epf">Index entries for sequences computed from exponents in factorization of n</a>
%F mu_1(n) = mu(n) = A008683(n).
%F mu_k(n) = sum_{d^k|n} mu_{k-1}(n/d^k)*mu_{k-1}(n/d), k>=2.
%F Multiplicative with a(p)=1, a(p^2)=-1 and a(p^e)=0 if e>=3. Dirichlet g.f. product_{primes p} (1+p^(-s)-p^(-2s)). - _R. J. Mathar_, Oct 31 2011
%F Sum_{n <= x} a(n) = kx + O(sqrt(x) log x), where k = 0.4282495... = A065464. - _Charles R Greathouse IV_, Jan 24 2018
%p A189021 := proc(n) local d, d1, d2; d1:=divisors(n); d2:=select(m->member(m^2, d1), d1); add(mobius(n/d^2)*mobius(n/d), d=d2) end; # _Peter Luschny_, Oct 30 2010
%p mu := proc(n,k) local d,a; if k = 1 then return numtheory[mobius](n) ; end if; a := 0 ; for d in numtheory[divisors](n) do if n mod (d^k) = 0 then a := a+procname(n/d^k,k-1)*procname(n/d,k-1) ; end if; end do: a ; end proc:
%p A189021 := proc(n) mu(n,2) ; end proc:
%t a[1] = 1; a[n_] := Sum[ Boole[ Divisible[n, d^2]]*MoebiusMu[n/d^2]*MoebiusMu[n/d], {d, Divisors[n]}]; Table[a[n], {n, 1, 100}] (* _Jean-François Alcover_, Jun 24 2013 *)
%t f[p_, e_] := Which[e == 1, 1, e==2, -1, e > 2, 0]; a[1] = 1; a[n_] := Times @@ f @@@ FactorInteger[n]; Array[a, 100] (* _Amiram Eldar_, Sep 21 2020 *)
%o (PARI) a(n)=if(n<2, 1, sumdiv(n, d, if(n%d^2, 0, moebius(n/d^2)*moebius(n/d)))) \\ _Benoit Cloitre_, Oct 03 2010
%o (Scheme) (define (A189021 n) (cond ((= 1 n) n) (else (* (case (A067029 n) ((1) 1) ((2) -1) (else 0)) (A189021 (A028234 n)))))) ;; (after the given multiplicative formula) - _Antti Karttunen_, Jul 18 2017
%o (Python)
%o from sympy import factorint, prod
%o def a(n): return 1 if n==1 else prod(1 if e==1 else -1 if e==2 else 0 for p, e in factorint(n).items())
%o print([a(n) for n in range(1, 51)]) # _Indranil Ghosh_, Jul 19 2017
%Y Cf. A008683, A053864, A189022, A189023.
%K sign,mult,easy
%O 1
%A _R. J. Mathar_, Apr 15 2011