TITLE: Continuous and discontinuous function problem
QUESTION [15 upvotes]: The following problem can be true?
Problem: For every positive integer $n>1$ there exists a function $ f\left( x \right)$ on $\mathbb{R}$ which satisfies both following conditions:
(i) $f\left( x \right),{\rm{ }}f\left( {f\left( x \right)} \right), \ldots ,{\rm{ }}f\left( { \ldots f\left( x \right) \ldots } \right)$ ( $ (n-1)$ times $ f $) discontinuous at every $x$ belong to $\mathbb{R}$.
(ii) $ f\left( { \ldots \left( {f\left( x \right) \ldots } \right)} \right)$ ( $n$ times $f$ ) continuous in $ \mathbb{R}$.

REPLY [2 votes]: Let $A_{n}$ denote the set of real numbers which solve an integer polynomial of degree $n$, but are not roots of any polynomial of degree $< n$. Then $A_{1} = \mathbb{Q}$, and $A_{2}$ is the set of all irrational (real) solutions to quadratic polynomials, etc. Let
\begin{align*}
f(x) & = \begin{cases}
0 & \textrm{if } x \not \in A_{1}, \ldots, A_{n}, \\
2 & \textrm{if } x \in A_{1} , A_{2} , \\
\sqrt{2} & \textrm{if } x \in A_{3} , \\
2^{1 / 3} & \textrm{if } x \in A_{4} , \\
\vdots & \vdots \\
2^{1 / (n - 1)} & \textrm{if } x \in A_{n} .
\end{cases}
\end{align*}
That should do it, I'm pretty sure.