General pentagonal numbers are given by:
$$p(t) = \frac{3t^2 - t}{2},$$
where $t \in \mathbb{Z}$. Note that for all $t$, $p(t) \geq 0$.
For some $n > 0$, how many pentagonal numbers are there less than $n$?
General pentagonal numbers are given by:
$$p(t) = \frac{3t^2 - t}{2},$$
where $t \in \mathbb{Z}$. Note that for all $t$, $p(t) \geq 0$.
For some $n > 0$, how many pentagonal numbers are there less than $n$?
On
Once $k$ is moderately large, $k^2$ will be rather small compared to $k^3$. You can do fixed point iteration. Start with $k_0=\sqrt[3]{2n}$, then iterate $k_{i+1}=\sqrt[3]{2n-k_i^2}$. It will converge quickly. As an example, if $k=100, n=5050$. We get $k_0\approx 100.33$ and it converges quickly to $k=100$
On
I'll assume the question in the title is what is wanted.
The pentagonal numbers form an increasing sequence:
$$p(1)<p(2)<p(3)<...<p(t)<...$$
If you want to find how many of these are smaller than $n$, you need to find the largest index $t$ such that:
$$p(1)<p(2)<p(3)<...<p(t)<n$$
Then we know that each of the pentagonal numbers $p(1)$ to $p(t)$ are smaller than $n$, and that all the remaining pentagonal numbers $p(t+1)$ etc are larger. The number of pentagonal numbers smaller than $n$ is then simply $t$ (because they are $p(1)$ to $p(t)$).
So what you need to find is the largest integer $t$ such that
$$p(t) = \frac{3t^2 - t}{2} < n$$
Note: If you want to include $p(0)=0$ in your count, just do the above and add $1$ to your answer.
The general pentagonal number for some input integer $x$ is: $$ p(x) = \frac{3x^2 - x}{2} $$
In general, $p(k) < p(-k)$ for some $k > 0$. This is because the parabola $p(x)$ is slightly shifted in the positive $x$ direction on the x-axis, and we are interested in integer inputs for $x$, so integer $-1$ will correspond to a slightly higher location on the left branch of the parabola than integer $1$'s corresponding point on the right branch.
So, let us focus on the sequence of numbers generated by the integers $k$ such that $1 \leq k$ and: $$ p'(k) = \frac{3k^2 + k}{2} $$
We want to find $k$ such that: \begin{align*} &\quad n - p'(k) = 0 \\ &\quad n - \frac{3k^2 + k}{2} = 0\\ &\Rightarrow k = \frac{-(1/2) \pm \sqrt{(1/4) - 4(3/2)(n)}}{3} \end{align*} We end up getting two solutions for $k$ anyway, and we can just accept both. After all, the negative $k$ will just end up giving us the number we would have gotten if we plugged in $-k$ into $p'(k)$, which would correspond to the $p(k)$ pentagonal number. Dropping the constants since as $n$ becomes large, they'll be dwarfed, we get: \begin{align*} 2k &\approx 2\sqrt{4(3/2)(n)}{3} \\ &\approx \sqrt{\frac{8}{3}n} \end{align*} Which is essentially what we are looking for.