%I #19 Nov 24 2023 12:38:41
%S 0,2,2,12,68,780,7782,137256,2130440,47895390,1010001010,28531167060,
%T 743044451340,25239592216020,797785000011174,31147773583410240,
%U 1157442765409226768,51702516367896047760,2185932446972586391986,109912203092239643840220,5255987282125313280008020
%N a(n) = Sum_{k=0..n} n^k * |(n - k | k)|, where (a | b) denotes the Kronecker symbol.
%H Wikipedia, <a href="https://en.wikipedia.org/wiki/Kronecker_symbol">Kronecker symbol</a>
%F a(n) = Sum_{k=0..n} [gcd(k, n) = 1] * n^k, where [] is the Iverson bracket.
%p KS := (n, k) -> NumberTheory:-KroneckerSymbol(n, k):
%p A367546 := n -> local k; add(n^k * abs(KS(n - k ,k)), k = 0..n):
%p seq(A367546(n), n = 0..20);
%t A367546[n_]:=If[n==0,0,Sum[n^k*Boole[CoprimeQ[n,k]],{k,0,n}]];Array[A367546,25,0] (* _Paolo Xausa_, Nov 24 2023 *)
%o (SageMath)
%o def a(n):
%o return sum(abs(kronecker_symbol(n - k, k)) * n^k for k in range(n + 1))
%o # Alternative: (For Python include 'import math' for math.gcd.)
%o def a(n):
%o cop = [int(gcd(k, n) == 1) for k in (0..n)]
%o return sum(p * n^k for k, p in enumerate(cop))
%o print([a(n) for n in range(21)])
%o (PARI) a(n) = sum(k=0, n, n^k*abs(kronecker(n-k, k))); \\ _Michel Marcus_, Nov 23 2023
%o (Python)
%o from math import gcd
%o def A367546(n): return sum(n**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, A367545.
%K nonn
%O 0,2
%A _Peter Luschny_, Nov 22 2023