Equation for value of p given x

56 Views Asked by At

I have a set of numbers:

$\begin{array}{r(22)}x \in \{ 1,& 2,& 3,& 4,& 5,& 6,& 7,& 8,& 9,& 10,& 11,& 12,& 13,& 14,& 15,& 16,& 17,& 18,& 19,& 20,& 21,& 22, \dotsc \} \\ p \in \{ 1,& 2,& 2,& 3,& 3,& 3,& 4,& 4,& 4,& 4,& 5,& 5,& 5,& 5,& 5,& 6,& 6,& 6,& 6,& 6,& 6,& 7, \dotsc \}\end{array}$

The first $x$ matches with the first $p$ and so on...

I am trying to find an equation that will give me the $p$ value given $x$, i have tried $p = \lceil (x-1)^{0.5} \rceil + 1$. It works for the first few values then stops...

Thanks

2

There are 2 best solutions below

2
On

$$\left\lceil\frac{-1+\sqrt{8x+1}}{2}\right\rceil$$

0
On

Look at it backwards. The highest value of $x$ for a given $p$ is: $$x_h = 1 + 2 +\ldots+ (p-1) + p$$

The sum of the first $p$ natural numbers is: $$\sum_{k=1}^p k = \frac 12 p(p+1) $$

Hence we have a quadratic. $$0 = p^2+p-2x_h \implies p = \frac{-1\pm\sqrt{1+8x_h}}{2}$$

Since $p>0, \forall x>0$ we discard the negative solutions: $$p= \frac{\sqrt{1+8x_h}-1}{2}$$

Since that is for the highest value of $x$ that gives integer $p$, we need to raise the result of lower values to the ceiling.

$$p=\left\lceil \frac{\sqrt{1+8x}-1}2 \right\rceil$$