Let
k be the least integer with
k2≥n. The function
f climbs one step at a time to the next perfect square, so
f(n)=k+(k2−n). The function
g climbs by
2s, preserving the parity of its argument, and
j2≡j(mod2), so
g(n)=j+(j2−n) where
j is the least integer with
j2≥n and
j≡n(mod2). If
k≡n(mod2) then
j=k and the ratio is
1; so we need
k≡n(mod2), in which case
j=k+1 and
g(n)−f(n)=(k+1)2−k2+1 =2k+2.
Then
7f=4g=4f+4(2k+2) gives
f=38(k+1), so
k≡2(mod3) and
n=k2+k−38(k+1), subject to
(k−1)2<n≤k2 and
n≡k(mod2).
For
k=2,5,8,11 the formula gives
n=−2,14,48,100, each failing
n>(k−1)2; for
k=14, n=170 is in range but has the same parity as
k. For
k=17, n=289+17−48=258, which satisfies
256<258≤289 and is even while
k is odd. Indeed
f(258)=17+31=48 and
g(258)=18+66=84, with
8448=74, so the least
n is
258.