login
A062022
a(n) = Sum_{k=1..n} Sum_{j=1..k} (prime(k) - prime(j))^2.
3
0, 1, 14, 59, 256, 581, 1298, 2287, 4004, 7329, 11338, 17915, 26660, 36637, 49406, 67239, 91252, 117585, 151730, 191819, 235112, 289013, 350842, 425919, 521300, 628001, 740666, 865899, 997744, 1143501, 1345454, 1565639, 1815068, 2074761
OFFSET
1,3
LINKS
FORMULA
From G. C. Greubel, May 04 2022: (Start)
a(n) = a(n-1) + n*prime(n)^2 + Sum_{k=1..n} prime(k)*(prime(k) - 2*prime(n)), with a(0) = a(1) = 0.
a(n) = n*Sum_{j=1..n} prime(j)^2 - (Sum_{j=1..n} prime(j))^2 = n*A024450(n) - A007504(n)^2. (End)
EXAMPLE
a(3) = (5-2)^2 + (5-3)^2 + (3-2)^2 = 14, sum of the squared differences of all pairs of the first 3 primes.
MAPLE
A062022 := proc(n)
local a, i, j ;
a := 0 ;
for j from 1 to n do
for i from 1 to j-1 do
a := a+(ithprime(j)-ithprime(i))^2 ;
end do:
end do:
a ;
end proc:
seq(A062022(n), n=1..10); # R. J. Mathar, Oct 03 2014
MATHEMATICA
a[n_]:= a[n]= n*Sum[Prime[k]^2, {k, n}] - (Sum[Prime[j], {j, n}])^2;
Table[a[n], {n, 50}] (* G. C. Greubel, May 04 2022 *)
PROG
(SageMath)
@CachedFunction
def a(n): return n*sum(nth_prime(j)^2 for j in (1..n)) - (sum(nth_prime(j) for j in (1..n)))^2
[a(n) for n in (1..50)] # G. C. Greubel, May 04 2022
CROSSREFS
KEYWORD
nonn
AUTHOR
Amarnath Murthy, Jun 02 2001
EXTENSIONS
More terms from Matthew Conroy, Jun 11 2001
STATUS
approved