How to find the next number in a sequence whose square root is a whole number

267 Views Asked by At

I've just rephrased the question a bit.

S(i=1 to n) is a set of n whole numbers where Square_Root(Si) is always a whole number.

Di(i=1 to n) is a set of differences such that: Si+Di = Sj where Square_Root(Sj) is a whole number and there no other whole number between Si and Sj whose square root is a whole number.

For a random value Si, I need to find the Di. Once I get the Di for a given Si, I can easily find the next value of D in the sequence.

I am a novice in mathematics and am writing a software program. Any help would be greatly appreciated.!

1

There are 1 best solutions below

2
On

You want to go from $k^2$ to $(k+1)^2$, so you do the following $$ (k+1)^2 - k^2 = 2k+1, $$ and so starting with $a_0=0$ (implies a square of $0^2=0$), the next one would be $$ a_1 = a_0 + 2\cdot 0 + 1 = a_0 + 1 = 1\\ a_2 = a_1 + 2\cdot 1 + 1 = a_1 + 3 = 4\\ a_3 = a_2 + 2\cdot 2 + 1 = a_2 + 5 = 9 $$

This way you can generate the entire sequence.

UPDATE

Starting at any random value $N$ which is a perfect square, compute the square root and set $k=\sqrt{N}$, then proceed as before, with $$ a_{k+1} = a_k+2k+1 $$