A Pythagorean triple consists of three positive integers a, b, and c, such that a2 + b2 = c2. Such a triple is commonly written (a, b, c), and a well-known example is (3, 4, 5). If (a, b, c) is a Pythagorean triple, then so is (ka, kb, kc) for any positive integer k. A primitive Pythagorean triple is one in which a, b and c are coprime.
Using this knowledge, we can create a sequence by chaining together the least lengths of triples, where the next element in the sequence is the hypotenuse (largest number) of the smallest primitive Pythagorean triple containing the previous element as the smallest one of its lengths.
Start with the smallest primitive Pythagorean triple (3, 4, 5). The sequence begins with 3
, and the hypotenuse (next element in the sequence) is 5
. Then find the smallest primitive Pythagorean triple with 5
as a leg, and you get (5, 12, 13). So the sequence continues with 13
.
Either output the sequence forever, or take an integer input n
and output the first n
elements of the sequence, either zero or one indexed.
You need to support output at least through and including 28455997
, but if the limit of the data type you are using was suddenly raised, it would need to work for that new limit. So you cannot hard code a list of numbers.
3
5
13
85
157
12325
90733
2449525
28455997
295742792965
171480834409967437
656310093705697045
1616599508725767821225590944157
4461691012090851100342993272805
115366949386695884000892071602798585632943213
12002377162350258332845595301471273220420939451301220405
Similar sequences (don't output these!):
12325
. \$\endgroup\$85
... its next term is3613
(can you guess what it is yet?) \$\endgroup\$