TITLE: Does $p\mid f(m)+f(n)\leftrightarrow p\mid f(m+n)$ imply $f(m+n)=f(m)+f(n)$?
QUESTION [5 upvotes]: Let $f:\mathbb{N}\to\mathbb{N}$ be a function such that:
$$(\forall p: \mathrm{~prime~})(\forall m,n\in\mathbb{N})(p\mid f(m)+f(n)\leftrightarrow p\mid f(m+n))$$
is $f$ linear?

by linear I mean:
$$(\forall m,n\in\mathbb{N})(f(m+n)=f(m)+f(n))$$

REPLY [3 votes]: There are many counterexamples which are not constant.
Take any partition of $\mathbb{N}$ into 2 nonempty sets $A, B$, and take
\begin{equation}
f(n)= \begin{cases} 6& \text{if} \, n \in A \\ 18& \text{if} \, n \in B \end{cases}
\end{equation}
Let me know if you want more elaborate counterexamples.