Suppose $f(x)$ defined in $\mathbb{R}$, then $f$ is continuous in $\mathbb{R}$ if and only if for every open set $G$, the set $f^{-1}(G)=\{x:f(x)\in G\} $ is open.
I have done necessity.
If $f$ is continuous and G is open. Then for $x_0\in f^{-1}(G)$,$f(x_0)\in G$,and $f$ is continuous hence $\exists U(x_0,\delta)$,such that for $x\in U(x_0,\delta)$,$f(x)\in G$. Thus $ U(x_0,\delta)\subset f^{-1}(G)$ which makes $f^{-1}(G)$ is an open set.
And now I have no ideal of the sufficiency.