Function Repository Resource:

ConsecutiveSquareSum

Source Notebook

Find integers representable as the sum of consecutive squares

Contributed by: Jan Mangaldan

ResourceFunction["ConsecutiveSquareSum"][n]

finds integers that can be represented as sums of both n and n+1 consecutive squares.

ResourceFunction["ConsecutiveSquareSum"][n,k]

finds k such integers.

Details

ResourceFunction["ConsecutiveSquareSum"][n] returns a tuple {p,q,t}, where t is the sum of squares of n consecutive integers starting from p, and n+1 consecutive integers starting from q.

Examples

Basic Examples (2) 

Find an integer that can be represented as the sum of two and three consecutive squares:

In[1]:=
ResourceFunction["ConsecutiveSquareSum"][2]
Out[1]=

Check that 365 satisfies this property:

In[2]:=
365 == 13^2 + 14^2 == 10^2 + 11^2 + 12^2
Out[2]=

Find four integers that can be represented as the sum of two and three consecutive squares:

In[3]:=
ResourceFunction["ConsecutiveSquareSum"][2, 4]
Out[3]=

Check all the results:

In[4]:=
Total[(#[[1]] + {0, 1})^2] == Total[(#[[2]] + {0, 1, 2})^2] == #[[3]] & /@ %
Out[4]=

Scope (2) 

Find five integers representable as the sum of 100 and 101 squares:

In[5]:=
ResourceFunction["ConsecutiveSquareSum"][100, 5]
Out[5]=

Verify the first example:

In[6]:=
Total[Range[20201, 20201 + 99]^2] == Total[Range[20100, 20100 + 100]^2] == 41008358350
Out[6]=

Version History

  • 1.0.0 – 10 February 2021

Source Metadata

Related Resources

License Information