# Find the nth term of the sequence.

#### anemone

##### MHB POTW Director
Staff member
A sequence of positive integers is defined as follows:

The first term is 1.
Then take the next two even numbers 2, 4.
Then take the next three odd numbers 5, 7, 9.
Then take the next four even numbers 10, 12, 14, 16 and so on.

Find the nth term of the sequence.

#### mathworker

##### Well-known member
let N be the largest number less than 'n' in the form $\frac{k(k+1)}{2}$
$$n=k^2+2(n-N)-1$$

But here we have to find N i have an approach ,
$$n>\frac{k^2+k}{2}$$
$$2n>k^2+k$$
so i thought of finding a perfect square which less than $$\displaystyle 2n$$ by at-least difference k or more than $$\displaystyle 2n$$ by difference less than k
And if $$\displaystyle n=N$$ then $$\displaystyle n=k^2$$
edit:changed n to 2n in last para and added some details

Last edited:

#### Albert

##### Well-known member
the last number of m'th row is $m^2$

the first number of m'th row is $(m-1)^2+1$

for 1+2+3+4+------------+(m-1)=$\dfrac {m^2-m}{2}$

$\therefore a_(\dfrac{m^2-m+2}{2})=(m-1)^2+1$

if $a_n$ locates at m'th row

let $\dfrac {m^2-m+2}{2} \leq n------(1)$

$(m-1)^2+1=m^2-2m+2\leq 2\times n-m$

$\therefore a_n=2\times n-max(m)$

here n $\in N$

and m must satisfy (1)

for example we want to find $a_{10}$

at first we must find max(m)

$\dfrac {m^2-m+2}{2} \leq 10$

$\therefore max(m)=4$

and we have $a_{10}=20-4=16$

from (1) $\dfrac {m^2-m+2}{2} \leq n$

$m^2-m+2-2n\leq 0$

$max(m)=int(\dfrac{1+\sqrt{8n-7}}{2})$

$a_n=2n-int(\dfrac{1+\sqrt{8n-7}}{2})$

Last edited:

#### Bacterius

##### Well-known member
MHB Math Helper
[JUSTIFY]Let this sequence be denoted $\left ( a_n \right )_{n = 1}^\infty$. It's easy to see that this sequence is predictably partitioned into "islands" of odd and even elements. These islands grow in size at a linear rate. Let each island be indexed by an integer $k$, such that, for instance, the island $\{ 1 \}$ is mapped to $k = 1$, the island $\{ 2, 4 \}$ is mapped to $k = 2$, and so on.

Given an integer $n$, we first have to find in which island $k$ the element $a_n$ is located. Due to the rate at which the islands grow, it is easy to see that the $k$th island starts at position:

$$n_k = 1 + \sum_{i = 1}^{k - 1} i = 1 + \frac{1}{2} (k - 1) k$$

That is, $a_{n_k}$ is the first element of the the $k$th island. And so $a_{n_k + k - 1}$ is the last element of the $k$th island, trivially.

[HR][/HR]

Suppose that $a_n$ is located in the $k$th island. Now, there must exist an $a_m$ such that $a_m$ is in the $k$th island, but $a_{m - 1}$ is not. In other words, it is the first element of the island. Then it follows that $m = n_k$. That is:

$$m = 1 + \frac{1}{2} (k - 1) k ~ ~ \implies ~ ~ k = \frac{1}{2} \left ( \sqrt{8m - 7} + 1 \right )$$

Clearly $k$ is an integer, so $8m - 7$ must be an odd perfect square. Since $m \leq n$, we deduce that $8m - 7$ is simply the largest odd perfect square less than (or equal to) $8n - 7$. Thus, we get:

$$8m - 7 = \mathcal{Q}^2 = \text{Largest odd perfect square less than or equal to } ~ 8n - 7$$

And this gives us the island we are looking for:

$$k = \frac{1}{2} \left ( \sqrt{\mathcal{Q}^2} + 1 \right ) = \frac{\mathcal{Q} + 1}{2}$$

It turns out that $\mathcal{Q}$ can be expressed more naturally using the floor function, which yields:

$$k = \left \lfloor \frac{\lfloor \sqrt{8n - 7} \rfloor + 1}{2} \right \rfloor$$

Observe that this floor function manipulation ignores the parity of $\lfloor \sqrt{8n - 7} \rfloor$ and assumes it is odd (which is what we want).

[HR][/HR]

Now that we have this island, we need to figure out the value of $a_n$. To do this, we work out the value of the last element of the island. We are smart, and we notice that this element must necessarily be a perfect square, due to the fact that the $n$th perfect square is the sum of the first $n$ odd numbers (look at the difference between terms within individual islands). In fact, the last element of the $k$th island is equal to $k^2$.

Using the result obtained a while ago, $a_{n_k + k - 1} = k^2$. Finally, within any island, the difference between each consecutive term is constant and equal to $2$. We already know the index of the term $a_n$ we are looking for, since it's, well, $n$. And we know that the last element of the island is at index $n_k + k - 1$.

Doing some simplifications:

$$n_k = 1 + \frac{1}{2} (k - 1) k ~ ~ \implies ~ ~ n_k + k - 1 = \frac{1}{2} (k - 1) k + k = \frac{k^2}{2} + \frac{k}{2}$$

Almost there! Now the difference between $n_k + k - 1$ and $n$ is thus:

$$\Delta = \frac{k^2}{2} + \frac{k}{2} - n$$

Notice that $\Delta$ is always nonnegative, since $a_n$ cannot be simultaneously inside the $k$th island and greater than the last element of the $k$th island. Using the fact that the difference between consecutive terms is $2$, we finally conclude that:

$$a_n = k^2 - 2 \Delta = k^2 - 2 \left ( \frac{k^2}{2} + \frac{k}{2} - n \right ) = 2n - k$$

Putting this all in terms of $n$ using the floor function trick above, this is equivalent to:

$$a_n = 2n - \left \lfloor \frac{\lfloor \sqrt{8n - 7} \rfloor + 1}{2} \right \rfloor$$

This can probably be simplified further, but I think it looks nice as it is

[HR][/HR]

Enumerating the first few terms of this sequence, we obtain:

$$\left ( a_n \right )_{n = 1}^\infty = \{ 1, 2, 4, 5, 7, 9, 10, 12, 14, 16, 17, 19, 21, 23, 25, 26, 28, 30, 32, 34, 36, \cdots \}$$

$$\blacksquare$$

[/JUSTIFY]

Last edited: