For which pairs of integers $(a, b)$ do there exist functions $f: \mathbb{Z} \rightarrow \mathbb{Z}$ and $g: \mathbb{Z} \rightarrow \mathbb{Z}$ obeying  
$$ f(g(x))=x+a \quad \text { and } \quad g(f(x))=x+b $$  
for all integers $x$ ?
The answer is if $a=b$ or $a=-b$. In the former case, one can take $f(x) \equiv x+a$ and $g(x) \equiv x$. In the latter case, one can take $f(x) \equiv -x+a$ and $g(x)=-x$. Now we prove these are the only possibilities. First: Claim - The functions $f$ and $g$ are bijections. Note also that for any $x$, we have
$$
\begin{aligned}
& f(x+b)=f(g(f(x)))=f(x)+a \\
& g(x+a)=g(f(g(x)))=g(x)+b .
\end{aligned}
$$
If either $a$ is zero or $b$ is zero, we immediately get the other is zero, and hence done. So assume $ab \neq 0$. If $|b|>|a|$, then two of
$$
\{f(0), f(1), \ldots, f(b-1)\} \quad(\bmod |a|)
$$
coincide, which together with repeatedly applying the first equation above will then give a contradiction to injectivity of $f$. Similarly, if $|a|>|b|$ swapping the roles of $f$ and $g$ (and $a$ and $b$) will give a contradiction to injectivity of $g$. This completes the proof.

Remark. Here is a way to visualize the argument, so one can see pictorially what is going on. We draw two parallel number lines indexed by $\mathbb{Z}$. Starting from 0, we draw a red arrow from 0 to $f(0)$, and then a blue arrow from $f(0)$ to $g(f(0))=b$, and then a red arrow from $b$ to $g(b)=f(0)+a$, and so on. These arrows can be extended both directions, leading to an infinite "squaretooth" wave. The following is a picture of an example with $a, b>0$.
![](https://cdn.mathpix.com/cropped/2024_11_19_10fe2e18e797a050a222g-05.jpg?height=358&width=1112&top_left_y=2134&top_left_x=478)
The problem is essentially trying to decompose our two copies of $\mathbb{Z}$ into multiple squaretooth waves. For this to be possible, we expect the "width" of the waves on the top and bottom must be the same - i.e., that $|a|=|b|$.

Remark. This also suggests how to classify all functions $f$ and $g$ satisfying the condition. If $a=b=0$ then any pair of functions $f$ and $g$ which are inverses to each other is okay. There are thus uncountably many pairs of functions $(f, g)$ here.

If $a=b>0$, then one sets $f(0), f(1), \ldots, f(a-1)$ as any values which are distinct modulo $b$, at which point $f$ and $g$ are uniquely determined. An example for $a=b=3$ is
$$
f(x)=\left\{\begin{array}{lll}
x+42 & x \equiv 0 & (\bmod 3) \\
x+13 & x \equiv 1 & (\bmod 3) \\
x-37 & x \equiv 2 & (\bmod 3),
\end{array} \quad g(x)=\left\{\begin{array}{lll}
x-39 & x \equiv 0 & (\bmod 3) \\
x+40 & x \equiv 1 & (\bmod 3) \\
x-10 & x \equiv 2 & (\bmod 3)
\end{array}\right.\right.
$$
The analysis for $a=b<0$ and $a=-b$ are similar, but we don't include the details here.