# Why are the last two numbers of this sequence never prime?

I had the idea to make a script that generates a pattern like this:

1
2 3
4 5 6
7 8 9 10


and so on. After that, I replaced every non-prime by a ‘-‘ character and every prime number by a ‘|’. The output begins like that:

-
||
-|-
|---
|-|--
-|-|--
-|-----
|-|-----
|---|-|--
-|-----|--
---|-|-----
|---|-|-----
|---|-----|--
-----|---|-|--
-|-|---|-------
------|---|-----


What I realized is that, with the exception of the second and third lines (possibly because of 2), on every line until 12000, the two last numbers are never prime. Obviously, one of them is even, but the odd one isn’t a prime number in any of these lines.

Is there a way to prove that this is true for any line? Is there any theorem that could help?

Great credit to you for having discovered this, because it is a known phenomenon presented in an unknown gem.

The last element on each of the lines is the sum of the first $$n$$ natural numbers (for example, $$1=1$$, $$3=1+2$$, $$6=1+2+3$$,$$10=1+2+3+4$$ etc.). As it turns out,the sum of the first $$n$$ natural numbers has a formula, given by $$\frac{n(n+1)}2$$. Therefore, the last number on every line is either divisible by the line number $$n$$ or its successor, $$n+1$$, whichever one is odd (one of them is odd).

For example, $$6$$ is divisible by its line number $$3$$.

$$10$$ is divisible by one more than its line number, $$5$$.

Which is why, unless you are on the second line, the last number is never going to be prime. In fact, the formula even gives its divisors.

Similarly, the second last number on each line is $$\frac{n(n+1)}{2} – 1 = \frac{n^2+n-2}{2} = \frac{(n+2)(n-1)}{2}$$, hence the factors of the second last number is the odd number out of $$n + 2$$ and $$n – 1$$, where $$n$$ is the row number. We can check this also:

$$9$$ is divisible by $$3$$, one less than $$4$$.

$$14$$ is divisible by $$7$$, $$2$$ more than $$5$$.

Hence, again the second to last number is not going to be prime.

I think I should add this: After some time, the fourth from last number is never going to be prime! (Think about this yourself).

After some time, the seventh from last number is never going to be prime! (Think about this yourself).

After some time, the eleventh from last number is never going to be prime! (Think about this yourself).

It is worth wondering about the nature of those elements which are not covered under the $$\frac{n(n+1)}{2} – (r-1)$$ scheme below. The point is, for those numbers , we take the $$r-1$$ on top as usual to form the number $$\frac{n(n+1) – 2r + 2}{2}$$, which we know is a natural number. The question is : is this composite or not?

What we do know is that for $$r = 1,2,4,7$$ etc. we get factorizations of the expression $$n(n+1) – 2r+2$$ into two linear terms in $$n$$, therefore we get composite numbers.

What is true, in the case of the other $$r$$s, is that we definitely will get infinitely many composite numbers while going through $$n(n+1) – 2r + 2$$. This is because every non-constant polynomial takes infinitely many composite values. In our case, for example, taking $$n = k(2r-2) + 1$$ for $$k \in \mathbb N$$, we see that $$n(n+1) – 2r+2 = (2r-2)((k(2r-2) + 1)k – 1)$$ is composite for $$r \geq 3$$. Therefore, for every $$r$$, there exist infinitely many rows such that the $$r$$th last number of that row is composite.

As for primality, the question is still open as to whether quadratic expressions(in one variable) which are not linearly factorable take infinitely many prime values. Therefore this question will remain open for some time, whether the $$r$$th last number of each row will stop containing primes after some time or will have infinitely many primes.