OFFSET
1,4
LINKS
David A. Corneth, Table of n, a(n) for n = 1..10000
Paul Erdos, Some Unconventional Problems in Number Theory, Mathematics Magazine, Vol. 52, No. 2, Mar., 1979, pp. 67-70. See Problem 12. p. 70.
FORMULA
a(p) = p-2, for p prime.
a(k^2 * m) = k * a(k * m) + 4 * (k - 1). - David A. Corneth, Nov 28 2018
EXAMPLE
a(1) and a(2) are 0, since we have an empty sum.
For a(3), the integers < 3, coprime to 3, are 1 and 2, so a(3) = (2-1)^2 = 1.
MATHEMATICA
a[n_] := Total[Differences[Select[Range[n], GCD[n, #]==1 &]]^2]; Array[a, 50] (* Amiram Eldar, Nov 28 2018 *)
PROG
(PARI) a(n) = {v = select(x->gcd(x, n)==1, vector(n, k, k)); sum(i=1, #v-1, (v[i+1] - v[i])^2); }
(PARI) a(n) = {my(res = 0, io = 1, in = 2); while(in < n, while(gcd(in, n) > 1, in++); res += (in - io)^2; io = in; in++); res}
first(n) = {my(res = vector(n)); for(i = 1, n, c = factorback(factor(i)[, 1]); if(c == i, res[i] = a(i), res[i] = res[c] * (i / c) + 4 * (i / c - 1))); res } \\ David A. Corneth, Nov 28 2018
CROSSREFS
KEYWORD
nonn
AUTHOR
Michel Marcus, Nov 28 2018
STATUS
approved