OFFSET
1,4
LINKS
Antti Karttunen, Table of n, a(n) for n = 1..20000
FORMULA
a(n) = Sum_{k=1..n, gcd(k,n)=1} (-1)^(k+1)*k.
If n even, a(n) = n*phi(n)/2.
a(p^k) = floor(p/2) - p + 1, where p is odd prime.
If n is odd and n > 1, a(n) = mu(rad(n)) * phi(rad(n))/2 where rad(n) is the radical of n and mu is the Mobius function. - Tung T. Nguyen, Nov 10 2022
MATHEMATICA
a[n_] := Sum[Boole[GCD[k, n] == 1] (-1)^(k + 1) k, {k, 1, n}]; Table[a[n], {n, 1, 65}]
oiei[n_]:=Module[{cp=Select[Range[n-1], CoprimeQ[#, n]&]}, Total[Select[ cp, OddQ]]-Total[ Select[cp, EvenQ]]]; Join[{1}, Array[oiei, 70, 2]] (* Harvey P. Dale, Apr 23 2022 *)
PROG
(PARI) a(n)={sum(k=1, n, -if(gcd(k, n)==1, (-1)^k*k))} \\ Andrew Howroyd, Sep 07 2019
CROSSREFS
KEYWORD
sign
AUTHOR
Ilya Gutkovskiy, Sep 07 2019
STATUS
approved