TITLE: Continuous functions with a certain condition
QUESTION [9 upvotes]: What is the class of continuous functions $f\colon \mathbb{R}\to\mathbb{R}$ which satisfy
$f(x)-f(y)\in\mathbb{Q}$ if and only if $x-y\in \mathbb{Q}$?

REPLY [7 votes]: Let $t$ be a rational number. Consider the function $g(x)=f(x+t)-f(x)$. Then $g$
is continuous also and takes values only in $\mathbb Q$, so $g$ is constant.
It follows that $g(x)=g(0)=f(t)-f(0)=c(t)$.
So we have
$$
f(x+t)=f(x)+c(t) \tag{1}
$$
for any real $x$ and rational $t$. Then $c$ is certainly linear, so there is
an $r\in {\mathbb Q}$ such that $c(t)=rt$ for any rational $t$. So $f(t)=f(0)+rt$
by taking $x=0$ in $1$.
The continuity of $f$ then implies that $f(t)=f(0)+rt$ for all $t$. Conversely,
functions of this form are clearly solutions. 
 UPDATE  (in answer to a comment) : here is a more detailed explanation
 of why $c$ is linear.
We have $c(t_1+t_2)=f(t_1+t_2)-f(0)$ (take $x=0$ in (1)), and
$c(t_1)=f(t_1)-f(0)$ (take $x=0$ in (1)), 
$c(t_2)=f(t_1+t_2)-f(t_1)$ (take $x=t_1$ in (1)). So
$c(t_1+t_2)=c(t_1)+c(t_2)$.