login
a(n) = Sum_{k=0..n} (-2)^k * |(n - k | k)|, where (a | b) denotes the Kronecker symbol.
3

%I #18 Nov 24 2023 12:38:32

%S 0,-1,-2,2,-10,10,-34,42,-170,114,-650,682,-2210,2730,-10794,6290,

%T -43690,43690,-141474,174762,-666250,449778,-2794154,2796202,-9054370,

%U 10168010,-44731050,29826162,-176859690,178956970,-545925250,715827882,-2863311530,1904682098

%N a(n) = Sum_{k=0..n} (-2)^k * |(n - k | k)|, where (a | b) denotes the Kronecker symbol.

%F a(n) = Sum_{k=0..n} [gcd(k, n) = 1] * (-2)^k, where [] is the Iverson bracket.

%p KS := (n, k) -> NumberTheory:-KroneckerSymbol(n, k):

%p A367545 := n -> local k; add((-2)^k * abs(KS(n - k ,k)), k = 0..n):

%p seq(A367545(n), n = 0..33);

%t A367545[n_]:=Sum[(-2)^k*Boole[CoprimeQ[n,k]],{k,0,n}];

%t Array[A367545,50,0] (* _Paolo Xausa_, Nov 24 2023 *)

%o (SageMath). # For Python include 'import math' for math.gcd.

%o def a(n):

%o cop = [int(gcd(i, n) == 1) for i in range(n + 1)]

%o return sum(p * (-2)^k for k, p in enumerate(cop))

%o print([a(n) for n in range(34)])

%o (PARI) a(n) = sum(k=0, n, (-2)^k*abs(kronecker(n-k, k))); \\ _Michel Marcus_, Nov 23 2023

%o (Python)

%o from math import gcd

%o def A367545(n): return sum((-(1<<k) if k&1 else 1<<k) for k in range(n+1) if gcd(n,k)==1) # _Chai Wah Wu_, Nov 24 2023

%Y Cf. A217831, A000010, A023896, A055034, A349136, A367544, A367546.

%K sign

%O 0,3

%A _Peter Luschny_, Nov 22 2023