# Perfect Squares of Sequences with offsets

#### tejolson

I wrote another program. It's kind of goofy posting this sort of stuff on the net.

Anyway, I was looking around for sequences where m^2+n^2 are a perfect square. I noticed the first one, 4/3, 7^2+24^2=25^2. And tried finding more with a calculator. When I couldn't find any more, I wrote a program to look for them.

The offset is the initial n value. The sequenceBase is the x in a(n) = xa(n-1)+a(n-2). The m becomes the a(n), the n the a(n-1). As you might guess these are all triangles, if you really want to make them into triangles, just use the formula m^2-n^2, 2mn, m^2+n^2. I also included the difference between the square root of the perfect square and the m value. I'm not sure why I did that, I just thought it would be more data for comparison. The prime factors of the differences are pretty interesting.

The offsets are comparable to Lucas Numbers (sequenceBase 1; offset = 1) to the Fibonacci series (sequenceBase = 1; offset = 1), and Pell Companion Numbers (offset = 2; sequenceBase = 2) to the Pell Number series (sequenceBase 2; offset = 1). You'll notice my offsets get much larger than 1 and 2.

Code:
import java.math.BigInteger;

public class sequenceTriangles {
public static void main (String[] args) {
BigInteger sequenceBase;
BigInteger sum=BigInteger.valueOf(1);
BigInteger m=BigInteger.valueOf(1);
BigInteger n=BigInteger.valueOf(1);
BigInteger square;
BigInteger perfectSquare;
BigInteger offset;
BigInteger counter = BigInteger.valueOf(1);
int terms;

terms = 6;
for (BigInteger q = BigInteger.valueOf(1); q.compareTo(BigInteger.valueOf(651400)) < 0; q=q.add(BigInteger.valueOf(1))) {//536403
offset = q;
for (BigInteger l = BigInteger.valueOf(1); l.compareTo(BigInteger.valueOf(52)) < 0; l=l.add(BigInteger.valueOf(1))) {//42
sequenceBase=l;
m=sequenceBase;

n=offset;

for (int i =0; i < terms; i++){
sum = m;
n = sum;
//System.out.print(m + " " + n);
System.out.println("Sequence Base: " + sequenceBase + " , term: " + i + ", offset: " +offset+ " -- " + m + "/" +n + ", Perfect Square: " + perfectSquare + " --> Difference: " + perfectSquare.subtract(m));
}

}
}
}
System.out.println("\nAmount of terms: " + counter);
}
public static BigInteger sqrt(BigInteger n)
{
if (n.signum() >= 0)
{
final int bitLength = n.bitLength();
BigInteger root = BigInteger.ONE.shiftLeft(bitLength / 2);

while (!isSqrt(n, root))
{
}
return root;
}
else
{
throw new ArithmeticException("square root of negative number");
}
}

private static boolean isSqrt(BigInteger n, BigInteger root)
{
final BigInteger lowerBound = root.pow(2);
return lowerBound.compareTo(n) <= 0 && n.compareTo(upperBound) < 0;
}
}

#### CRGreathouse

Forum Staff
These are called Pythagorean triples.

#### tejolson

Yup, I guess calling them triangles wasn't clear enough. But it's actually 2 Pythagorean Triples, that are part of a sequence. I guess since all of these types of sequences have triangles, it's kind of redundant to mention that.

Sequence Base: 2 , term: 1, offset: 1 -- 12/5, Perfect Square: 13 --> Difference: 1
Sequence Base: 1 , term: 1, offset: 2 -- 4/3, Perfect Square: 5 --> Difference: 1
Sequence Base: 1 , term: 5, offset: 4 -- 45/28, Perfect Square: 53 --> Difference: 8

$$\displaystyle 12^2 + 5^2 = 13^2$$
$$\displaystyle 12^2 - 5^2, 2 * 12 * 5, 12^2 + 5^2$$
$$\displaystyle 119^2 + 120^2 = 13^4$$

$$\displaystyle 4^2 + 3^2 = 5^2$$
$$\displaystyle 4^2 - 3^2, 2 * 4 *3, 4^2 + 5^2$$
$$\displaystyle 7^2 + 24^2 = 5^4$$

$$\displaystyle 45^2+28^2=53^2$$
$$\displaystyle 45^2-28^2,2*45*28,45^2+28^2$$
$$\displaystyle 1241^2+2520^2=53^4$$

Sequence Base: 21 , term: 2, offset: 499406 -- 220932815/10496808, Perfect Square: 221182033 --> Difference: 249218

$$\displaystyle 220932815^2+10496808^2=221182033^2$$
$$\displaystyle 220932815^2-10496808^2,2*220932815*10496808,220932815^2+10496808^2$$
$$\displaystyle 48701125765635361^2+4638178679909040^2=221182033^4$$

#### tejolson

The Pell Number ones are my favourite. Is it wrong to have a favourite? They end up as part of this list because the offset forces it.

Sequence Base: 1 , term: 1, offset: 2 -- 4/3, Perfect Square: 5 --> Difference: 1
Sequence Base: 1 , term: 1, offset: 19 -- 21/20, Perfect Square: 29 --> Difference: 8
Sequence Base: 1 , term: 1, offset: 118 -- 120/119, Perfect Square: 169 --> Difference: 49
Sequence Base: 1 , term: 1, offset: 695 -- 697/696, Perfect Square: 985 --> Difference: 288
Sequence Base: 1 , term: 1, offset: 4058 -- 4060/4059, Perfect Square: 5741 --> Difference: 1681
Sequence Base: 1 , term: 1, offset: 23659 -- 23661/23660, Perfect Square: 33461 --> Difference: 9800
Sequence Base: 1 , term: 1, offset: 137902 -- 137904/137903, Perfect Square: 195025 --> Difference: 57121

$$\displaystyle m+n=k$$
$$\displaystyle m^2+n^2=l^2$$
$$\displaystyle (\sum\limits_{i=1}^{k-1} i)^2 + (\sum\limits_{i=1}^k i)^2=(k*l)^2$$
$$\displaystyle (\sum\limits_{i=1}^6 i)^2 + (\sum\limits_{i=1}^7 i)^2=(7*5)^2$$
$$\displaystyle (\sum\limits_{i=1}^{40} i)^2 + (\sum\limits_{i=1}^{41} i)^2=(41*29)^2$$
$$\displaystyle (\sum\limits_{i=1}^{238} i)^2 + (\sum\limits_{i=1}^{239} i)^2=(239*169)^2$$
$$\displaystyle (\sum\limits_{i=1}^{1392} i)^2 + (\sum\limits_{i=1}^{1393} i)^2=(1393*985)^2$$
$$\displaystyle (\sum\limits_{i=1}^{8118} i)^2 + (\sum\limits_{i=1}^{8119} i)^2=(8119*5741)^2$$
$$\displaystyle (\sum\limits_{i=1}^{47320} i)^2 + (\sum\limits_{i=1}^{47321} i)^2=(47321*33461)^2$$
$$\displaystyle (\sum\limits_{i=1}^{275806} i)^2 + (\sum\limits_{i=1}^{275807} i)^2=(275807*195025)^2$$

#### tejolson

I forgot to mention in the previous post that the hypotenuses in this case are also triangular numbers.

$$\displaystyle (\sum\limits_{i=1}^{k-1} i)^2 + (\sum\limits_{i=1}^{k} i)^2 = (\sum\limits_{i=1}^{k^2} i)$$