Testing whether a number is pentagonal : comparison between two formulas I'm programmer by trade but starting to get interested in math in my spare time.  I decided to learn the basics by working my way through the problems at Project Euler.
On this problem I needed a function to check if a number was a pentagonal determined by the formula:
$$p_n=\frac{n(3n-1)}{2}$$
So I went about creating a function that accepts Pn and returns n and came up with:
$$n= \left\lceil{\frac{\sqrt{2P_n}}{\sqrt{3}}}\right\rceil$$
Or in JavaScript for the inquisitive:
let n = Math.ceil(Math.sqrt(Pn * 2) / Math.sqrt(3));

I tested it and it checked out. I went online to see if others are using this formula for finding n but it turns out another method is widely used:
$$n=\frac{\sqrt{24P_n+1}+1}{6}$$
My formula and this one appear to agree for positive integers.
Is my own formula something interesting or something most mathematicians would consider, obvious, pointless or otherwise uninteresting? If so, why? I found it pretty much by observing outputted values at different stages of working through the top formula and reasoning out something that worked in reverse then testing it.
Is there a better or more formal approach for finding such a formula (the inverse function, right)? Also, how do I go about proving (edit: or disproving) that my formula works for all positive integers of Pn?
 A: To begin with, the "correct one" (i.e. the one I'd recommend using and the one I would look for if I did the problem by myself) is the one you found on the internet. You get it by applying the quadratic formula to the equation $$\frac{3n^2-n}2-p_n=0$$
The reason why $$\left\lceil\sqrt{\frac23 y}\,\right\rceil=\frac{\sqrt{24y+1}+1}{6}$$ whenever $y$ is a pentagonal number (if it isn't, then the RHS is not a positive integer) is that, with some algebraic manipulation, $$\frac{\sqrt{24y+1}+1}{6}-\sqrt{\frac23y}=\color{blue}{\frac16}+\color{red}{\frac{1}{36\left(\sqrt{\frac23 y+\frac1{36}}+\sqrt{\frac23y}\right)}}$$
Which is very close to $\dfrac16<1$ as $y$ grows. Moreover, the $36$ in the second denominator dumps the value of the red fraction for the first integer values of $y$. Putting all together, you can infer that, for $y\ge1$, $$\frac{\sqrt{24y+1}+1}{6}-\frac13< \sqrt{\frac23 y}<\frac{\sqrt{24y+1}+1}{6}$$
So, when $\frac{\sqrt{24y+1}+1}{6}$ is an integer, the ceiling gives the correct rounding.
A: To put it in simple words, you are asking if the following equation is true for every $n\in\mathbb{N}$:
$$\left\lceil{\frac{\sqrt{2\frac{n(3n-1)}{2}}}{\sqrt{3}}}\right\rceil=\frac{\sqrt{24\frac{n(3n-1)}{2}+1}+1}{6}$$

Let's simplify this equation a bit:
$$\left\lceil{\frac{\sqrt{n(3n-1)}}{\sqrt{3}}}\right\rceil=\frac{\sqrt{12n(3n-1)+1}+1}{6}$$

And a bit more:
$$\left\lceil{\sqrt{\frac{n(3n-1)}{3}}}\right\rceil=\frac{\sqrt{12n(3n-1)+1}+1}{6}$$

At this point, note that we can get rid of the $\lceil\dots\rceil$ by adding $\frac{n}{3}$ to the expression inside the $\sqrt\dots$:
$$\color\red{\left\lceil{\sqrt{\frac{n(3n-1)}{3}}}\right\rceil=\sqrt{\frac{n(3n-1)}{3}+\frac{n}{3}}}$$

So the original equation becomes:
$$\sqrt{\frac{n(3n-1)}{3}+\frac{n}{3}}=\frac{\sqrt{12n(3n-1)+1}+1}{6}$$

Or simply:
$$n=\frac{\sqrt{12n(3n-1)+1}+1}{6}$$

Multiply by $6$ each side of the equation:
$$6n=\sqrt{12n(3n-1)+1}+1$$

Subtract $1$ from each side of the equation:
$$6n-1=\sqrt{12n(3n-1)+1}$$

Raise to the power of $2$ each side of the equation:
$$(6n-1)^2=12n(3n-1)+1$$

Simplify it, and Voilà:
$$36n^2-12n+1=36n^2-12n+1$$

Please note that the equation marked red is not necessarily true for $n<1$.
