cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

A062022 a(n) = Sum_{k=1..n} Sum_{j=1..k} (prime(k) - prime(j))^2.

Original entry on oeis.org

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

Views

Author

Amarnath Murthy, Jun 02 2001

Keywords

Examples

			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.
		

Crossrefs

Programs

  • 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 *)
  • 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

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)

Extensions

More terms from Matthew Conroy, Jun 11 2001