Determining a polynomial $p$ from its image of rationals. Let $f$ and $g$ be polynomials with rational coefficients, and let $F$ and $G$ denote the sets of values of $f$ and $g$ at rational numbers. Prove that $F = G$ holds if and only if $f(x) = g(ax + b)$ for some suitable rational numbers $a \not= 0$ and $b$.

This is a problem I found from "Contests in Higher Mathematics" whose problems are from the Miklos Schweitzer Competitions. I have found the problems in this competition deeply satisfying to think about and I would recommend for the reader to check them out
I was hoping to get a hint for the solution. Please do not spoil the problem for me. I am only looking for a nudge.
 A: *

*$f(x)=\sum_{n=0}^N c_n x^n$. For $v_p(1/b)=k$ large enough we have $v_p(f(b))= v_p(c_N)-Nk$.
Thus, from $f(\Bbb{Q})$ we know $N$ and $v_p(c_N)\bmod N$.
That is to say we know the image of $c_N$ in $\Bbb{Q^*/ \pm Q}^{*N}$.


*If $f(\Bbb{Q})=g(\Bbb{Q})$ then let $g_2(x)=\pm g(ax)$ where $a$ and $\pm $ are chosen such that the leading coefficient of $g_2$ is equal to $c_N$.
In fact we can assume the sign is $+$: if $N$ is odd then replace $a$ by $-a$, if $N$ is even then check if $g(\Bbb{Q})$ is bounded above or below to deduce the sign of the leading coefficient of $g$.
Let $f_3(x)=f_2(x+r_f),g_3(x)=g_2(x+r_g)$ where $r_f,r_g$ are chosen such that the coefficient of $x^{N-1}$ is $0$.
There is some integer $d$ such that  both $f_4(x)=c_N^{-1} d^{N} f_3( x/d),g_4(x)=c_N^{-1} d^{N} g_3(x/d)$ are $\in \Bbb{Z}[x]_{monic}$.


*$f_4(n)\in \Bbb{Z}$ iff $n\in \Bbb{Z}$.
$f_4$ is determined by $n,f_4(n),\ldots,f_4(n+N)$.

*

*If $N$ is odd:
For $n$ large enough $f_4(n),\ldots,f_4(n+N)$ are $N+1$ consecutive integers in $f_4(\Bbb{Q})\cap \Bbb{Z}$.
From $f_4(\Bbb{Q})\cap \Bbb{Z}$ we can pick $N+1$ large enough consecutive integers to get $f_4(n),\ldots,f_4(n+N)$ for some unknown $n$. Whence $f_4(\Bbb{Q})\cap \Bbb{Z}$ tells us $f_4$ up to a shift by an integer.


*If $N$ is even and $f_4(x)\ne f_4(-x)$. Wlog, replacing $f_4$ by $f_4(-x)$ if needed we can assume that $f_4(n)>f_4(-n)$ for $n$ large enough.
Then, for $n$ large enough (as the coefficient of $x^{N-1}$ is $0$) $f_4(-n),f_4(n),f_4(-n-1),f_4(n+1),\ldots,f_4(-n-N),f_4(n+N)$ are $2N+2$ consecutive integers in $f_4(\Bbb{Q})\cap \Bbb{Z}$.
Taking one of two of such consecutive integers tells us either $f_4(n),\ldots,f_4(n+N)$ or $f_4(-n),\ldots,f_4(-n-N)$ for some unknown $n$, which tells either $f_4(x)$ or $f_4(-x)$ up to a shift.


*If $f_4(x)=f_4(-x)$ then (since we know $N=\deg(f_4)$) this can be seen from the asymptotic of $f_4(\Bbb{Q})\cap \Bbb{Z}$ and it is similar to the odd $N$ case.




*ie. $f(\Bbb{Q})=g(\Bbb{Q})$ implies $f_4(\Bbb{Q})=g_4(\Bbb{Q})$ so that $f_4(x)=g_4(\pm x+k)$ for some $k$ and $f(x)= g(ax+b)$.
