Find the least $n$ such that $f(n)/g(n)=4/7$ 
Let $f(n)$ and $g(n)$ be functions satisfying $$f(n)=\cases{\sqrt{n} \hspace{50pt} \sqrt{n} \in \mathbb{N} \\ 1+f(n+1) \hspace{14pt} \text{otherwise}} $$
$$g(n)=\cases{\sqrt{n} \hspace{50pt} \sqrt{n} \in \mathbb{N} \\ 2+g(n+2) \hspace{14pt} \text{otherwise}}$$
for positive integers $n$. Find the least positive value of $n$ such that $\dfrac{f(n)}{g(n)}=\dfrac47$.

I found the values for $f$ and $g$ till $n=9$, I noticed that $f(n)=g(n)$ happened at $n=1,2,4,5,7,9$ and for some values it also happened that if $f(a)=b$, then $f(b)=a$. I don't know if that is useful in anyway. I can't see how to approach the problem.
Please give some hints.

I can not believe the number of arithmetic errors I made.  All inexcusable. but.
Let $n > 0$ so there is a $k$ so that $(k-1)^2 < k \le n^2$ and let $j = k^2 - n$.
Then $$f(n) = f(k^2-j)= 1 + f(k^2-j+1) = 2+f(k^2 - j + 2) =.... =j + f(k^2 -j + j) = j + f(k^2) = j + k$$. (That holds if $j=0$.)
Now similarly if $j$ is even then $g(n) = j +k$ as well.  But if $j$ is odd then.
$$g(k^2 - j) = (j-1) + g(k^2 - 1) = (j+1) + g(k^2 + 1) = (j + 2k + 1) + g(k^2+ 2k + 1) = (j+2k +1) + g((k+1)^2) = (j+2k +1) + (k+1) = j + 3k + 2$$.
So if $\frac {f(n)}{g(n)} \ne 1$ we must have $j$ is odd and  $\frac {f(n)}{g(n)} = \frac {j+k}{j + 3k + 2}$.
So we need $\frac {j+k}{j + 3k + 2} = \frac {4M}{7M}$ and
$j + k = 4M; j + 3k + 2 = 7M$ and $j$ is odd.  And ... arithmetic the bane of mathematicians.
$j= 4M - k$ (so $k$ is odd)
$4M - k + 3k + 2 = 4m + 2k + 2 = 7M$ so $k = \frac {3M-2}2$.
A bit of manipulation we can see than $M$ is divisible by $4$ as $k$ is odd. ($\frac {3M-2}2 = 2w -1\implies 3M=4m$).
Plugging in $M=4w$ we get
$k = \frac {12w-2}2 = 6w -1$ and $j = 16M -k = 10w + 1$.
But we must also have that $j < k^2 - (k+1)^2 = 2k-1$ so $10w + 1 < 12w -3$ so $w > 2$.
Now $w = 3$ and we have $k=17$ and $j = 31$ and $n = 17^2 - 31 > 17^2 -34 +1 = 16^2$.
And $f(17^2 - 31) = 31 + f(17^2) = 48 = 4\cdot 12$.
And $$g(17^2 -31) = 30 + g(17^2 -1)=32 + g(17^2+1)=32+34 + g(17^2 + 34 + 1)=66+g(18^2) = 84 = 7\cdot 12$$.
So $n = 17^2 - 31 = 258$ is the smallest such $n$.
(To minimimize $(k-1)^2 < n=k^2 -j < k^2$ where $n = k^2 -j=(6w-1)^2-(10w + 1)=36w^2 -20w=4w(6w-5)$ we must minimize $w$.)
