TITLE: Let $f:\mathbb{R}\to\mathbb{R}$ be a continuous function that satisfies $f(q+1/n)=f(q)$ for every $q\in\mathbb{Q}$ and for every $n\in\mathbb{N}$.
QUESTION [10 upvotes]: Question: Let $f:\mathbb{R}\to\mathbb{R}$ be a continuous function that satisfies $f(q+\frac{1}{n})=f(q)$ for every $q\in\mathbb{Q}$ and for every $n\in\mathbb{N}$. Show that $f$ must be a constant function.


Solution: Substituting $q-\frac{1}{n}$ for $q$ in $$f(q+\frac{1}{n})=f(q),$$ we have $$f(q)=f(q-\frac{1}{n})$$ for all $q\in\mathbb{Q}$ and for all $n\in\mathbb{N}$. Let the original relation be denoted by $(*)$ and the derived relation be denoted by $(**)$.
Now select any positive rational number $q=\frac{r}{s},$ where $r,s\in\mathbb{N}$. Thus, by repeated application of $(**)$, we have $$f\left(\frac{r}{s}\right)=f\left(\frac{r-1}{s}\right)=f\left(\frac{r-2}{s}\right)=\cdots=f\left(\frac{0}{s}\right)=f(0).$$
Next select any negative rational number $q=\frac{r}{s}$, where $r\in\mathbb{Z}_{\le 1}$ and $s\in\mathbb{N}.$ Thus, by repeated application of $(*),$ we have $$f\left(\frac{r}{s}\right)=f\left(\frac{r+1}{s}\right)=f\left(\frac{r+2}{s}\right)=\cdots=f\left(\frac{0}{s}\right)=f(0).$$
Thus, for all $q\in\mathbb{Q}$, we have $f(q)=f(0)$.
Next select any irrational number $q'$. We know that there exists a convergent sequence $(x_n)_{n\ge 1}$ of rational numbers such that it converges to $q'$. Now since $f$ is continuous on $\mathbb{R}$, implies that it is continuous at $q'$. Thus, by the sequential definition of limit we can conclude that the sequence $f(x_n)$ converges to $f(q').$ Now note that $f(x_n)=f(0)$, for all $n\in\mathbb{N}$. This implies that $f(x_n)$ converges to $f(0)$, which in turn implies that $f(q')=f(0)$. Now since $q'$ is arbitrary, therefore, $f(q')=f(0)$ for all irrational numbers $q'$.
Thus, we can conclude that $f(x)=f(0)$ for all $x\in\mathbb{R}$, that is $f$ is a constant function.
Is this solution correct and rigorous enough and is there any other way to solve the problem?

REPLY [2 votes]: This looks solid to me; as far as alternative solutions, there's one that skips the process of explicitly showing all rationals equivalent first: consider any rational $p$, and an arbitrary real $x$. Now, set $p_0=p$, and for each $i$ let $p_{i+1}=p_i\pm\frac1{n_i}$, where $n_i = \max\left(1,\left\lfloor\dfrac1{|x-p_i|}\right\rfloor\right)$ and the sign is chosen according to whether $p_i\lt x$ or $p_i\gt x$. You should be able to show that $p_i$ converges to $x$, and $f(p_i)=f(p)$ for all $i$, so by continuity $f(x)=f(p)$ for arbitrary $x$.
Note that this isn't necessarily a faster solution; showing the convergence isn't entirely trivial. It also has a lot of commonality with your approach, but I think it's distinct enough to warrant mention.