Problem: Let $f(n)$ and $g(n)$ be functions satisfying \[f(n) = \begin{cases}\sqrt{n} & \text{ if } \sqrt{n} \text{ is an integer}\\ 1 + f(n+1) & \text{ otherwise} \end{cases}\] and \[g(n) = \begin{cases}\sqrt{n} & \text{ if } \sqrt{n} \text{ is an integer}\\ 2 + g(n+2) & \text{ otherwise} \end{cases}\] for positive integers $n$ . Find the least positive integer $n$ such that $\tfrac{f(n)}{g(n)} = \tfrac{4}{7}$

Solution: To begin, note that if $n$ is a perfect square, $f(n)=g(n)$ , so $f(n)/g(n)=1$ , so we must look at values of $n$ that are not perfect squares (what a surprise). First, let the distance between $n$ and the first perfect square greater than or equal to it be $k$ , making the values of $f(n+k)$ and $g(n+k)$ integers. Using this notation, we see that $f(n)=k+f(n+k)$ , giving us a formula for the numerator of our ratio. However, since the function of $g(n)$ does not add one to the previous inputs in the function until a perfect square is achieved, but adds values of two, we can not achieve the value of $\sqrt{n+k}$ in $g(n)$ unless $k$ is an even number. However, this is impossible, since if $k$ was an even number, $f(n)=g(n)$ , giving a ratio of one. Thus, $k$ must be an odd number.
Thus, since $k$ must be an odd number, regardless of whether $n$ is even or odd, to get an integral value in $g(n)$ , we must get to the next perfect square after $n+k$ . To make matters easier, let $z^2=n+k$ . Thus, in $g(n)$ , we want to achieve $(z+1)^2$
Expanding $(z+1)^2$ and substituting in the fact that $z=\sqrt{n+k}$ yields:
\[(z+1)^2=z^2+2z+1=n+k+2\sqrt{n+k}+1\]
Thus, we must add the quantity $k+2z+1$ to $n$ to achieve a integral value in the function $g(n)$ . Thus.
\[g(n)=(k+2z+1)+\sqrt{n+k+2\sqrt{n+k}+1}\]
However, note that the quantity within the square root is just $(z+1)^2$ , and so:
\[g(n)=k+3z+2\]
Thus, \[\frac{f(n)}{g(n)}=\frac{k+z}{k+3z+2}\]
Since we want this quantity to equal $\frac{4}{7}$ , we can set the above equation equal to this number and collect all the variables to one side to achieve
\[3k-5z=8\]
Substituting back in that $z=\sqrt{n+k}$ , and then separating variables and squaring yields that
\[9k^2-73k+64=25n\]
Now, if we treat $n$ as a constant, we can use the quadratic formula in respect to $k$ to get an equation for $k$ in terms of $n$ (without all the squares). Doing so yields
\[\frac{73\pm\sqrt{3025+900n}}{18}=k\]
Now, since $n$ and $k$ are integers, we want the quantity within the square root to be a perfect square. Note that $55^2=3025$ . Thus, assume that the quantity within the root is equal to the perfect square, $m^2$ . Thus, after using a difference of squares, we have \[(m-55)(m+55)=900n\] Since we want $n$ to be an integer, we know that the $LHS$ should be divisible by five, so, let's assume that we should have $m$ divisible by five. If so, the quantity $18k-73$ must be divisible by five, meaning that $k$ leaves a remainder of one when divided by 5 (if the reader knows LaTeX well enough to write this as a modulo argument, please go ahead and do so!).
Thus, we see that to achieve integers $n$ and $k$ that could potentially satisfy the problem statement, we must try the values of $k$ congruent to one modulo five. However, if we recall a statement made earlier in the solution, we see that we can skip all even values of $k$ produced by this modulo argument.
Also, note that $k=1,6$ won't work, as they are too small, and will give an erroneous value for $n$ . After trying $k=11,21,31$ , we see that $k=31$ will give a value of $m=485$ , which yields $n=\boxed{258}$ , which, if plugged in to for our equations of $f(n)$ and $g(n)$ , will yield the desired ratio, and we're done.

Answer:  258